Save PDFs to Local Storage in UWP

Using PSPDFKit for Windows, you can export your document in a variety of ways. This guide covers the simplest one: using a StorageFile.

Exporting a Document

In our API, the word export is synonymous with save. The snippet below allows you to export the currently open document to its original source:

var storageFile = PDFView.Document?.DocumentSource.GetFile();

if (storageFile != null) {
    await PDFView.Document.ExportAsync(file);
}

As you can see, the DocumentSource holds information on the original StorageFile. But you can also prompt the user with the Windows FileSavePicker:

var savePicker = new FileSavePicker
{
    FileTypeChoices =
    {
        { "PDF", new List<string> { ".pdf" } }
    }
    DefaultFileExtension = ".pdf",
    SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
    SuggestedFileName = "PSPDFKitSavedFile",
};

var file = await savePicker.PickSaveFileAsync();

if (file != null)
{
    await PDFView.Document.ExportAsync(file);
}

Exporting Options

For more control over exporting documents, use our DocumentExportOptions class. It can be included in the Document.ExportAsync method:

var exportOptions = new DocumentExportOptions
{
    Flattened = FlattenAnnotations,
    Incremental = IncrementalSave,
    Format = Format.Pdf
};

await PDFView.Document.ExportAsync(file, exportOptions);

For more information on all of the available exporting options, please refer to our API documentation.

Moreover, the PdfView also supports automatically saving changes. More information can be found in the relevant guide.