I am using the C++ library PoDoFo (http://podofo.sourceforge.net/) and what I am trying to achieve is embedding a PDF page into a new blank PDF document.
The documentation for the constructor I am using is here: http://podofo.sourceforge.net/doc/html/classPoDoFo_1_1PdfXObject.html#ad60d2bcfa51676961ce09ad274a6a6df
This is what my code currently looks like:
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();
When constructing the PdfXObject from an existing PDF document PdfError is thrown, perhaps I have made a mistake because I am new to C++ or there is potentially a bug in PoDoFo.
The error that is thrown has the following message:
PoDoFo encounter an error. Error: 48 ePdfError_ChangeOnImmutable
Error Description: Changing values on immutable objects is not allowed.
Callstack:
What is the correct way to construct a PdfXObject from an existing PDF page and embed it into a new PDF document?