Hi Zyx

Haha, I totally miss your link in first response, blind as I am :)

I think I got it pretty much working now using my code from before. If you
see anything wrong in the code, please let me know (leaks, wrong handling
of whatever, etc).

Thanks for the help!

/Jacob

PoDoFo::PdfMemDocument* createSinglePageDocument(const
PoDoFo::PdfMemDocument& sourceDocument, const bool drawPageSemantics, const
PoDoFo::PdfColorRGB& backgroundcolor)
{
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);
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++)
{
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();

try
{
PdfXObject* xobj = new PdfXObject(spage->GetCropBox(), document);
document->FillXObjectFromDocumentPage(xobj, sourceDocument, idx, false);
painter.DrawXObject(spage->GetPageSize().GetLeft(), dY, xobj);
}
catch (const PdfError& ex)
{
logEvent(EID_ERROR,
StringHelp::local8ToText(PdfError::ErrorMessage(ex.GetError())));
}
}

painter.FinishPage();

return document;
}



On Mon, Feb 18, 2019 at 12:58 PM zyx <z...@gmx.us> wrote:

> On Mon, 2019-02-18 at 10:40 +0100, Jacob Pedersen wrote:
> > //                    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
>
>         Hi,
> as the first step you need to copy pages from the source PDF to the
> destination PDF, it copies all needed, including resources (copy all in
> one step, rather than one-by-one, especially if you want all pages).
> Then you need to work with those pages in the destination PDF.
>
> The GetContentsForAppending() is really not what you want.
>
> The similar code I gave a link to earlier shows you how to do this. You
> can avoid litePDF, it is "just a wrapper" on top of PoDoFo in this
> code, thus you can look into what the litePDF does and mimic that.
>         Bye,
>         zyx
>
>
>
> _______________________________________________
> 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

Reply via email to