DocumentJsonFormatter

Exports and imports changes made to annotations and form fields of a PdfDocument into a JSON string. JSON strings created and read by this class are also used by PSPDFKit Instant.

The JSON generated by this class represents a set of all annotation, and form field changes to the original document (i.e. the document in the state in which it was loaded). It comprises all added annotations, changes to existing annotations, deleted annotations, and also values entered into form fields. More info on the JSON format is available in our online guides.

One possible use case for using this is syncing changes made to the document without having to transmit the entire PDF document.

Functions

Link copied to clipboard
suspend fun exportDocumentJson(document: PdfDocument, outputStream: OutputStream, instantJsonVersion: InstantJsonVersion = InstantJsonVersion.entries.last())

Suspends while exporting document JSON for the given document. The serialization work is performed on the caller's coroutine context.

Link copied to clipboard
fun exportDocumentJsonAsync(document: PdfDocument, outputStream: OutputStream, instantJsonVersion: InstantJsonVersion = InstantJsonVersion.entries.last()): Completable

Asynchronously exports all (unsaved) changes to annotations, and form elements made since opening the given document into a JSON string. This JSON string contains a pdfId and can only be imported on the exact same document again. Trying to import it in a different document will throw a DocumentJsonFormatterException. One possible use case for document JSON is syncing document changes without having to send the entire PDF.

Link copied to clipboard
fun exportDocumentJsonBlocking(document: PdfDocument, outputStream: OutputStream, instantJsonVersion: InstantJsonVersion = InstantJsonVersion.entries.last())

Exports all (unsaved) changes to annotations, and form elements made since opening the given document into a JSON string. This JSON string contains a pdfId and can only be imported on the exact same document again. Trying to import it in a different document will throw a DocumentJsonFormatterException. One possible use case for document JSON is syncing document changes without having to send the entire PDF.

Link copied to clipboard
suspend fun importDocumentJson(document: PdfDocument, dataProvider: ERROR CLASS: Symbol not found for DataProvider)

Suspends while importing a document JSON and applying its changes to the given document. The JSON has to be provided by the given dataProvider. Callers are responsible for choosing an appropriate kotlinx.coroutines.CoroutineDispatcher (for example kotlinx.coroutines.Dispatchers.IO).

Link copied to clipboard
fun importDocumentJsonAsync(document: PdfDocument, dataProvider: ERROR CLASS: Symbol not found for DataProvider): Completable

Asynchronously imports a document JSON and applies its changes to the given document. The JSON has to be provided by the given dataProvider. Deserialization will start upon subscribing to the Completable returned by this method. The returned completable does not operate on any particular scheduler. If you want to run the deserialization process on a background thread, consider calling Completable.subscribeOn on the completable before subscribing.

Link copied to clipboard
fun importDocumentJsonBlocking(document: PdfDocument, dataProvider: ERROR CLASS: Symbol not found for DataProvider)

Imports a document JSON and applies its changes to the given document. The JSON has to be provided by the given dataProvider. Deserialization is performed on the current thread. When trying to import from the main thread, consider using importDocumentJson instead to avoid that your application becomes unresponsive.