user756079
user756079

Reputation: 341

Foxit PDF SDK - delete page increases document size

The DeletePage function found in the Foxit SDK allows a page to be deleted from a PDF. When a page is deleted and the document saved, the file size of the output document (with fewer pages) is larger than the original.

This can be seen with the PDF sample app which ships with the SDK:

$ ./simple_sample/bin/rel_gcc/pdfpage_organization 
...
Success: Use <rb> mode to open the file InsertPages.pdf and associate it with a stream.
Success: Create the file object.
Success: Open file successfully .
Success: Load PDF document successfully.
Success: Get page with index 1.
Success: Delete page with index 1.
Using extension implementation to open the file.
Success: Use <wb> mode to open the file SourcePage_delete.pdf and associate it with a stream.
Success: Create the file object.
Success: The PDF document save to SourcePage_delete.pdf.

Examining the output:

ll simple_sample/input_files/SourcePage.pdf -rw-r--r--@ 1 richard staff 92K Dec 17 2013 simple_sample/input_files/SourcePage.pdf

ll simple_sample/output_files/pdfpage_organization/SourcePage_delete.pdf -rw-r--r--@ 1 richard staff 96K Jun 23 10:22 simple_sample/output_files/pdfpage_organization/SourcePage_delete.pdf

SourcePage_delete.pdf does have one less page as expected, but is 4k bigger. I can get the same result deleting 99 pages from a 100 page document, i.e. the file size does not reflect the page count.

Upvotes: 0

Views: 438

Answers (2)

Huy Tran
Huy Tran

Reputation: 1

In the latest Foxit PDF SDK 6.4 for Linux the save method supports e_SaveFlagRemoveRedundantObjects. Usually when you delete a page, it is just referenced in the PDF structure. If you set this flag, it will just remove any object that is not reference to in the PDF.

Upvotes: 0

Chris Haas
Chris Haas

Reputation: 55427

Based on the sample documents that you've provided and @MihaiIancu's comment you are saving an incremental PDF update which basically just appends new information to the end of your existing file.

According to the Foxit SDK site the function FSPDF_Doc_StartSaveToFile takes a flag for the third parameter which is FSPDF_SAVEFLAG_INCREMENTAL, FSPDF_SAVEFLAG_NOORIGINAL, FSPDF_SAVEFLAG_REMOVESECURITY or FSPDF_SAVEFLAG_OBJECTSTREAM. In your case I would think that FSPDF_SAVEFLAG_NOORIGINAL should do what you're looking for. If you're not using this function directly there should still hopefully be a wrapper that takes one of these parameters.

Upvotes: 1

Related Questions