c++ - 仅从 PDF 文件中复制必要的对象

标签 c++ pdf podofo

我有一个超过 100 页的巨大 PDF 文件,我想将它们分成单个 PDF 文件(每个文件仅包含一页)。问题是,PoDoFo 不只是复​​制页面,而是复制整个文档,因为引用(因此 100 个 PDF 文件中的每一个都与 100 页 PDF 的大小相同)。 relevant mailing list post可以找到,遗憾的是没有提供解决方案。

InsertPages函数的源码中有说明:

This function works a bit different than one might expect. Rather than copying one page at a time - we copy the ENTIRE document and then delete the pages we aren't interested in.

We do this because
1) SIGNIFICANTLY simplifies the process
2) Guarantees that shared objects aren't copied multiple times
3) offers MUCH faster performance for the common cases

HOWEVER: because PoDoFo doesn't currently do any sort of "object garbage collection" during a Write() - we will end up with larger documents, since the data from unused pages will also be in there.

我尝试了几种方法来仅复制相关对象,但每一种都失败了。

  • 复制所有页面并删除不相关的页面
  • 使用 XObject 包装:FillXObjectFromDocumentPageFillXObjectFromExistingPage
  • 逐对象复制
  • RenumberObjectsbDoGarbageCollection = true 一起使用

但他们都没有成功。有人对这个问题有想法或可行的解决方案吗?

最佳答案

唯一的解决办法是使用另一个 PDF 库。或者等待垃圾回收实现。

问题在您提到的引用中说明:

> during a Write() - we will end up with larger documents, since the
> data from unused pages will also be in there.

这意味着 podofo 始终将整个 PDF 内容放入您的文件中,无论如何。整个 PDF 都在那里,您只是看不到它的一部分。

关于c++ - 仅从 PDF 文件中复制必要的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55283985/

相关文章:

c++ - 将 vector 迭代器传递给模板函数

c++ - C++ 游戏编程中的 Direct-X

PHP 从 MySQL 数据库转换为 PDF

php - 从sql数据库生成pdf报告

c++ - 我可以在列表后面的初始化列表中使用初始化的 C++ 类成员吗?

C++11 有没有办法静态测试方法访问级别?

file - FDM(免费下载管理器)如何确定文件的日期和时间?

c++ - PoDoFo c++ PDF库,润色字符

pdf - 使用 PoDoFo 或其他开源软件进行 PDF 预检程序?

C++ - 需要关于如何正确设计多文件程序的建议