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 with the PSPDFDocumentSaveOptionForceRewrite save option as follows:

try [.forceRewrite])
[document saveWithOptions:@{PSPDFDocumentSaveOptionForceRewrite: @YES} error:&error]