Hi Zyx

I tried to follow what you suggest and it seems to work, however the fil is
now triple size instead of double (still missing lines+rects) :) I probably
am doing something wrong?

/Jacob

document->InsertPages(sourceDocument, 0, sourceDocument.GetPageCount());

// b. traverse the pages in the new document and create XObject-s for each
of them;
std::map<int, PdfXObject*> xobjs;
for (int idx = 0, count = document->GetPageCount(); idx < count; idx++)
{
PdfPage* spage = document->GetPage(idx);
PdfXObject* xobj = new PdfXObject(spage->GetCropBox(), document);
xobjs[idx] = xobj;
}

// c. delete all the pages with the PdfPagesTree::DeletePage() (this will
delete them from the list of pages, but they will still be part of the
document)
for (int idx = document->GetPageCount() - 1; idx >= 0; idx--)
document->GetPagesTree()->DeletePage(idx);

// d. create a new page(s) and fill it/them with XObject-s as before.
PdfPainter painter;
painter.SetPage(document->CreatePage(rect));
// second pass to copy source pages to destination single page
double dY = rect.GetHeight();
for (int idx = 0, count = sourceDocument.GetPageCount(); idx < count; idx++)
{
const PdfPage* spage = sourceDocument.GetPage(idx);
dY -= spage->GetPageSize().GetHeight();
PdfXObject* xobj = xobjs[idx];
document->FillXObjectFromDocumentPage(xobj, sourceDocument, idx, false);
painter.DrawXObject(spage->GetPageSize().GetLeft(), dY, xobj);
}
painter.FinishPage();



On Mon, Feb 18, 2019 at 1:53 PM zyx <[email protected]> wrote:

> On Mon, 2019-02-18 at 13:37 +0100, Jacob Pedersen wrote:
> > Seems like I copy over redundant stuff using my simple approach.
>
>         Hi,
> you might want to do something like this:
> a) copy the pages with this or the like:
>    PdfMemDocument::InsertPages(src, 0, src->GetPageCount());
> b) traverse the pages in the new document and create XObject-s
>    for each of them;
> c) delete all the pages with the PdfPagesTree::DeletePage() (this will
>    delete them from the list of pages, but they will still be part of
>    the document)
> d) create a new page(s) and fill it/them with XObject-s as before.
>
> Eventually, to avoid caveats of page copying (yes, there are some) you
> can:
> - open the source file with PdfMemDocument
> - make the changes as in b), c), d)
> - save the PdfMemDocument into a new file.
> This approach might not always work, like with encrypted documents and
> possibly some other.
>         Bye,
>         zyx
>
>
>
> _______________________________________________
> Podofo-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to