Foxit SDK中的DeletePage函数允许从PDF中删除页面。当删除页面并保存文档时,输出文档(页面较少)的文件大小比原始文档大。
这可以在SDK附带的PDF示例应用程序中看到:
$ ./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.
检查输出:
会simple_sample/input_file/SourcePage.pdf-rw-r——r——@ 1 richard staff 92K 2013年12月17日simple_sample/input_files/SourcePage.pdf
会simple_sample/output_file 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确实比预期少了一个页面,但是大了4k。我可以从100页的文档中删除99页得到相同的结果,即文件大小不反映页面数。
根据您提供的示例文档和@MihaiIancu的评论,您将保存增量PDF更新,基本上只是将新信息附加到现有文件的末尾。
根据Foxit SDK站点,函数FSPDF_Doc_StartSaveToFile
为第三个参数FSPDF_SAVEFLAG_INCREMENTAL
, FSPDF_SAVEFLAG_NOORIGINAL
, FSPDF_SAVEFLAG_REMOVESECURITY
或FSPDF_SAVEFLAG_OBJECTSTREAM
取一个标志。在你的情况下,我认为FSPDF_SAVEFLAG_NOORIGINAL
应该做你正在寻找的。如果您不直接使用此函数,则仍然应该有一个接受这些参数之一的包装器。
在最新的Foxit PDF SDK 6.4 for Linux中,保存方法支持e_saveflagremoveredundanobjects。通常当您删除一个页面时,它只是在PDF结构中被引用。如果您设置此标志,它将删除PDF中未引用的任何对象。