使用PoDoFo构建PdfXObject
Constructing PdfXObject using PoDoFo
我正在使用C++库PoDoFo(http://podofo.sourceforge.net/)我试图实现的是将一个PDF页面嵌入到一个新的空白PDF文档中。
我正在使用的构造函数的文档如下:http://podofo.sourceforge.net/doc/html/classPoDoFo_1_1PdfXObject.html#ad60d2bcfa51676961ce09ad274a6a6df
这就是我的代码目前的样子:
PoDoFo::PdfMemDocument existingDocument(filename);
PoDoFo::PdfStreamedDocument *newDocument = new PoDoFo::PdfStreamedDocument("new_document.pdf");
PoDoFo::PdfPage *newPage = newDocument->CreatePage(PoDoFo::PdfRect(0.0,0.0,300.0,300.0));
PoDoFo::PdfXObject *XObjectFromPage;
XObjectFromPage = new PoDoFo::PdfXObject(existingDocument, 1, newDocument);
PoDoFo::PdfPainter *painter = new PoDoFo::PdfPainter();
painter->SetPage(newPage);
painter->DrawXObject (50, 50, XObjectFromPage,1);
painter->FinishPage();
newDocument->Close();
当从现有的PDF文档构建PdfXObject时,抛出了PdfError,也许我犯了一个错误,因为我是C++新手,或者PoDoFo中可能存在漏洞。
抛出的错误有以下消息:
PoDoFo encounter an error. Error: 48 ePdfError_ChangeOnImmutable
Error Description: Changing values on immutable objects is not allowed.
Callstack:
从现有的PDF页面构造PdfXObject并将其嵌入到新的PDF文档中的正确方法是什么?
要将现有页面加载到XObject中,请使用类似的方法(srcDoc和g_outputdoc是PdfMemDocuments):
PdfPage* srcPage(srcDoc->GetPage(pageNumber));
//create XObject owned by outputDoc with size of srcPage
PdfXObject* xobject = new PdfXObject(srcPage->GetCropBox(), g_outputDoc)));
//fill the xObject with the content of the page + all references and ressources used on this page
g_outputDoc->FillXObjectFromDocumentPage(xobject , *srcDoc, pageNumber, false);
你的嵌入部分是正确的。只需使用pdfPaint绘制对象:-)
这个方法的优点是所有的引用和资源都被复制了。糟糕的是,每次都会复制所有引用和所有资源;)即使您在其他页面中嵌入了相同的资源。。。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 构建一个由C和C++文件组成的库
- llvm构建器向基本块添加终止符
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 如何跨平台将二进制资源构建到程序中?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 如何解决 Ninja c++ 构建和执行问题
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 用CMake构建C++协议
- 使用PoDoFo构建PdfXObject