我正在使用 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 文档的正确方法是什么?