Growing PDF File Size
In some cases, you might experience a large increase in PDF file size when saving documents. This happens especially when using image annotations with large images and triggering a save of a document often.
This increase in file size is due to incremental saving, which PSPDFKit uses by default if it’s not configured in another way. Incremental saving always appends changes to the end of a document and never deletes anything. Incremental saving is used by default since it’s faster than rewriting an entire document, and usually, the file size increase is almost unnoticeable. As a result, it could be that the data of an image annotation is written and stored in a PDF multiple times.
Rewrite Document When Saving
To prevent the document file size from growing, you can trigger a non-incremental document save, which will rewrite the entire document instead of appending changes at the end.
This can be done by manually saving the document and setting the
incrementalSave property of the
false as follows:
1 2 3
val incrementalSave = false val options = DocumentSaveOptions(null, null, incrementalSave, null) document.saveIfModified(options)
1 2 3 4 5
final boolean incrementalSave = false; final DocumentSaveOptions options = DocumentSaveOptions( null, null, incrementalSave, null ); document.saveIfModified(options);