Auto Save PDF Files in React Native
PSPDFKit for React Native automatically saves a modified open document to your device’s local storage. You can also disable automatic saving and manually save the changes. Note that files are saved locally on your device, and no server is required.
Auto Save
PSPDFKit will automatically save changed, created, or deleted annotations and bookmarks on several occasions. In practice, this means that automatic saving will be performed when:
-
The application goes into the background
-
A configuration change occurs (for example, change of device orientation, change of locale, added keyboard)
-
The
PSPDFKitView
is fully covered by anotherView
-
The document on the
PSPDFKitView
is changed -
A document will be digitally signed
Each time a document is saved, the onDocumentSaved()
event is called:
onDocumentSaved={(event) => {
alert("Document was saved!");
}}
If there were no new changes to save, the event won’t be called.
Disable Automatic Saving
To disable automatic saving, set the disableAutomaticSaving
prop to true
, like so:
<PSPDFKitView document={DOCUMENT} disableAutomaticSaving={true} ref="pdfView" fragmentTag="PDF1" />
Manual Saving
Saving can always be triggered from the main thread by calling save()
on the current document:
await this.pdfRef?.current?.getDocument().save();
For more details and sample code, refer to the ManualSave.tsx
example from our Catalog example project.