Sunday, March 6, 2011

Combining two PDF files in C++

In C++ I'm generating a PDF report with libHaru. I'm looking for someway to append two pages from an existing PDF file to the end of my report. Is there any free way to do that?

Thanks.

From stackoverflow
  • You can use the Ghostscript utility pdf2ps to convert the PDF files to PostScript, append the PostScript files, and then convert them back to a PDF using ps2pdf.

    Troy Howard : As much as I love Ghostscript, this solution is really a kludge for anything other than a one-off. That's a really big hammer for such a simple task.
  • Try PoDoFo

    http://podofo.sourceforge.net/

    You should be able to open both of the PDFs as PDFMemDocuments using PDFMemDocument.Load( filename ). Then, aquire references to the two pages you want to copy and add to the end of the document using InsertPages, or optionally, remove all but the last two pages of the source document, then call PDFDocument.Append and pass the culled document. Hard to say which would be faster or more stable.

    Hope that helps, Troy

    Imbue : I ended up using the PoDoFo with the InsertPages method. It seems to actually delete all but the needed pages internally. It also crashes on some PDF files, but it works on simple tests and should be OK for my purposes. Thanks.

0 comments:

Post a Comment