Hi Zyx Thanks for the input which got me to write the following code. I cannot get it to work fully. I get the correct page size with lines, but actual pages are not copied over. Perhaps you can spot my error? Also it's not clear which pointers I should delete, as documentation does not state this.
PoDoFo::PdfMemDocument* PdfPageAppender::createSinglePageDocument(const PoDoFo::PdfMemDocument& sourceDocument, const bool drawPageSeparatorLine) { PdfMemDocument* document = new PdfMemDocument(); // first pass to find size of destination single page PdfRect rect; for (int idx = 0, count = sourceDocument.GetPageCount(); idx < count; idx++) { const PdfPage* spage = sourceDocument.GetPage(idx); const PdfRect pagesize = spage->GetPageSize(); if (pagesize.GetWidth() > rect.GetWidth()) rect.SetWidth(pagesize.GetWidth()); rect.SetHeight(rect.GetHeight() + pagesize.GetHeight()); } PdfPage* page = document->CreatePage(rect); PdfPainter painter; painter.SetPage(page); // second pass to copy source pages to destination single page double dY = 0; for (int idx = 0, count = sourceDocument.GetPageCount(); idx < count; idx++) { PdfPage* spage = sourceDocument.GetPage(idx); try { // PdfXObject* xobj = new PdfXObject(spage->GetObject()); // <- Exception: ePdfError_InvalidDataType (20) PdfXObject* xobj = new PdfXObject(spage->GetContentsForAppending()); // <- Nothing, except the lines, gets drawn on target, but Acrobat Reader shows an error when opening destination PDF painter.DrawXObject(0, dY, xobj); if (drawPageSeparatorLine) { // TODO: set color and line settings (dashed) painter.DrawLine(0, dY, rect.GetWidth(), dY); } dY += spage->GetPageSize().GetHeight(); } catch (const PdfError& ex) { logEvent(EID_ERROR, StringHelp::local8ToText(PdfError::ErrorMessage(ex.GetError()))); } } painter.FinishPage(); return document; } Thanks in advance! /Jacob On Mon, Feb 18, 2019 at 8:46 AM zyx <z...@gmx.us> wrote: > On Fri, 2019-02-15 at 13:14 +0100, Jacob Pedersen wrote: > > Can this type of merge be done? > > Hi, > yes, it can be done. > > I guess you want a bit more detailed response, thus: you can use the > original pages as XObject-s and draw them into your new pages. Drawing > a line is a primitive operation supported by the PDF standard. > > I do not know whether any of the PoDoFo tools or examples provide any > such code, I'm sorry. [1] > Bye, > zyx > > [1] Something similar, but not the same, is here: > https://litepdf.sourceforge.io/pagesperpage.cpp.html > > > > _______________________________________________ > Podofo-users mailing list > Podofo-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/podofo-users >
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users