Hi
No, I'm totally new to Podofo and did not realize that there were two
different fill functions. :)
I got it working now, however I'm not sure which constructor you refer to
or how this can make the code simpler. I'd be grateful for pointers on
making code faster and simpler. I added delete of the XObject's and since
it does not blow up I guess it's fine, but I have not tested for leaks as
such.
For reference this works pretty good with text-only test file (grows just 1
kb), however a file with images it grows from 109 to 117 kb, so still room
for improvement perhaps?
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);
document->FillXObjectFromExistingPage(xobj, idx, false);
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));
painter.SetStrokeStyle(ePdfStrokeStyle_Dot);
painter.SetStrokeWidth(1.0);
painter.SetStrokingColor(0.5, 0.5, 0.5); // could be option
painter.SetColor(backgroundcolor); // fillrect
// 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);
if (drawPageSemantics)
{
if (idx > 0)
painter.DrawLine(0, dY, rect.GetWidth(), dY);
painter.Rectangle(spage->GetPageSize().GetWidth(), dY -
spage->GetPageSize().GetHeight(), rect.GetWidth() -
spage->GetPageSize().GetWidth(), spage->GetPageSize().GetHeight());
painter.Fill();
}
dY -= spage->GetPageSize().GetHeight();
painter.DrawXObject(spage->GetPageSize().GetLeft(), dY, xobjs[idx]);
delete xobjs[idx];
}
painter.FinishPage();
On Mon, Feb 18, 2019 at 2:46 PM zyx <[email protected]> wrote:
> On Mon, 2019-02-18 at 14:12 +0100, Jacob Pedersen wrote:
> > 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?
>
> Hi,
> I'm sorry, but did you read the developer documentation of
> FillXObjectFromDocumentPage()? And for
> FillXObjectFromExistingPage()? That's quite obvious why the document is
> so large when you look at it.
>
> You might also want to use a PdfXObject constructor which "Create a new
> XObject from an existing page". That will make your code simpler.
>
> I'm not sure of the PdfXObject instance ownership, that would need some
> runtime testing.
> 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