java.lang.Object | |
↳ | com.pspdfkit.document.formatters.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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static void |
exportDocumentJson(PdfDocument document, OutputStream outputStream)
Exports all (unsaved) changes to annotations, and form elements made since opening the given
document into a JSON string. | ||||||||||
static Completable |
exportDocumentJsonAsync(PdfDocument document, OutputStream outputStream)
Asynchronously exports all (unsaved) changes to annotations, and form elements made since
opening the given
document into a JSON string. | ||||||||||
static void |
importDocumentJson(PdfDocument document, DataProvider dataProvider)
Imports a document JSON and applies its changes to the given
document . | ||||||||||
static Completable |
importDocumentJsonAsync(PdfDocument document, DataProvider dataProvider)
Asynchronously imports a document JSON and applies its changes to the given
document . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
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.
The generated JSON is written to outputStream
. Serialization is performed on the
current thread. Avoid calling this method on the main thread and consider using exportDocumentJsonAsync(PdfDocument, OutputStream)
instead to avoid that your application
becomes unresponsive.
The method will throw a DocumentJsonFormatterException
when encountering an
unexpected error while exporting the JSON.
Exporting of compound documents changes is not supported. This method will throw an exception if called with a compound document (i.e. a document having more than one document source).
document | The PdfDocument to serialize. This must not be a compound document. |
---|---|
outputStream | The OutputStream to which the JSON should be written. |
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.
The generated JSON is written to outputStream
. Serialization 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 serialization process on a
background thread, consider calling subscribeOn(Scheduler)
on the
completable before subscribing.
The returned completable will emit a DocumentJsonFormatterException
when
encountering an unexpected error while exporting the JSON.
Exporting of compound documents is not supported. This method will throw an exception if called with a compound document (i.e. a document having more than one document source).
document | The PdfDocument to serialize. This must not be a compound document. |
---|---|
outputStream | The OutputStream to which the JSON should be written. |
Completable
that will start the JSON export once its subscribe()
method is called.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 importDocumentJsonAsync(PdfDocument, DataProvider)
instead to avoid that your application
becomes unresponsive.
The method will throw a DocumentJsonFormatterException
when encountering an
unexpected error while importing the JSON.
Importing JSON to compound documents is not supported. This method will throw an exception if called with a compound document (i.e. a document having more than one document source).
document | The PdfDocument to which the JSON should be imported. This must not
be a compound document. |
---|---|
dataProvider | The DataProvider which serves the document JSON. |
DocumentJsonFormatterException | if trying to import document JSON created with a different document, or other error occurs while importing. |
---|
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 subscribeOn(Scheduler)
on the
completable before subscribing.
The returned completable will emit a DocumentJsonFormatterException
when
encountering an unexpected error while importing the JSON.
Importing JSON to compound documents is not supported. This method will throw an exception if called with a compound document (i.e. a document having more than one document source).
document | The PdfDocument to which the JSON should be imported. This must not
be a compound document. |
---|---|
dataProvider | The DataProvider which serves the document JSON. |
Completable
that will start the JSON import once its subscribe()
method is called.DocumentJsonFormatterException | if trying to import document JSON created with a different document, or other error occurs while importing. |
---|