Save as PDFs on Android

It’s not uncommon for customers to want a setup where a document is read-only but users can still edit it and then use the Save As functionality to save the modified document to a new location. PSPDFKit supports saving documents with the Save As functionality.

To use the Save As functionality:

  • Add a custom Save As button to the toolbar.

  • On button click, start a file picker with the Intent.ACTION_CREATE_DOCUMENT action. Either implement it yourself following general Android guidelines, or use our internal file picker, which is accessible via the thumbnailGrid (which can be accessed from either the PdfActivity class or the PdfUIFragment class). Our internal picker must be used with RxJava.

When the new file name is received, call one of the save functions from the PdfDocument class with it. We support synchronous (save) and asynchronous (saveAsync) saving. Both methods are available either only with the file path, or with specific saving options:

getPSPDFKitViews()
    .getThumbnailGridView()
    .getFilePicker()
    .getDestinationUri(Intent.ACTION_CREATE_DOCUMENT)
    .subscribe(
        // `onSuccess` (a file was selected).
        (uri) -> {
            // Call one of our saving methods here.
            document.save(uri.getPath());
        },
        // `onError` (something happened).
        (throwable) -> {

        },
        // `onComplete` (== filepicker operation was canceled).
        () -> {

        }
    );