我正在使用C++库PoDoFo (http://podofo.sourceforge.net/),我试图实现的是将一个PDF页面嵌入到一个新的空白PDF文档中。
我使用的构造函数的文档如下: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文档PdfError构建PdfError时,可能我犯了一个错误,因为我对C++并不熟悉,或者PoDoFo中有一个潜在的bug。
引发的错误包含以下消息:
PoDoFo encounter an error. Error: 48 ePdfError_ChangeOnImmutable
Error Description: Changing values on immutable objects is not allowed.
Callstack:从现有的PDF页面构建PdfXObject并将其嵌入新的PDF文档的正确方法是什么?
发布于 2015-12-18 09:17:01
要将现有页面加载到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);你的嵌入部分是对的。只需使用pdfPainter :-)绘制对象
这种方法的优点是所有的引用和资源都被复制了。不好的地方是,所有的引用和所有的资源每次都被复制;)即使您将相同的重新源嵌入到其他页面中.
https://stackoverflow.com/questions/34167450
复制相似问题