Save PDFs to Local Storage on Android

PSPDFKit for Android automatically saves changes made to a document to your device’s file system. This default behavior can be disabled using the autosaveEnabled method of the PdfConfiguration.Builder class:

val configuration = PdfConfiguration.Builder()
    .autosaveEnabled(false)
    .build()
final PdfConfiguration configuration = new PdfConfiguration.Builder()
    .autosaveEnabled(false)
    .build();

ℹ️ Note: If not explicitly specified, all examples in this guide save the document automatically on device.

Once autosaving is disabled, you can take full control of when the document is saved by calling the save or saveIfModified method of the PdfDocument class. You can access the instance of a document using the getDocument method of PdfFragment like so:

val document = activity.requirePdfFragment().document ?: return

// Manually save the document.
document.saveIfModified()
final PdfDocument document = activity.requirePdfFragment().getDocument();
if (document == null) return;

// Manually save the document.
document.saveIfModified();