How to save a PDFDoc in PDFNet for Windows Store apps using javascript

32 views
Skip to first unread message

Tomas Hofmann

unread,
May 21, 2014, 3:26:44 PM5/21/14
to pdfne...@googlegroups.com
Q: How do I save a file using javascript with PDFNet for Windows Store apps.

A: The functions below describe a hypothetical save button and save as button.
Note that pdfDoc is a global variable of the current document, and pdfDocStream is the current variable for the stream that is opened as the doc.

function save_click()
{
if (!pdfDoc)
{
return;
}

pdfDoc.saveAsync().then(function () {
});
return;

}

function saveAs_click()
{
if (!pdfDoc) {
return;
}

// Create the picker object and set options
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.viewMode = Windows.Storage.Pickers.PickerViewMode.list;
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;

savePicker.fileTypeChoices.insert("PDF", [".pdf"]);

// Open the picker for the user to pick a file
savePicker.pickSaveFileAsync().then(function (file) {
if (file) {

file.openAsync(Windows.Storage.FileAccessMode.readWrite).then
(
function (filestream) {
var filter = new pdftron.Filters.RandomAccessStreamFilter(filestream);

pdfDoc.saveAsync(filter, pdftron.SDF.SDFDocSaveOptions.e_remove_unused).then(function () {
if (pdfDocStream) { // close the old stream
pdfDocStream.close();
}

pdfDocStream = filestream;
});
}
);

} else {
// file didn't load.
}
});
}

Reply all
Reply to author
Forward
0 new messages