How to reuse a page from one PDF document into another PDF document?

I'm trying to add an image that I have on the file system as a PDF into a PDF that I'm creating on the fly. I tried to use the Image class, but it seems that it does not work with PDFs (only JPEG, PNG or GIF). How can I create an element from an existing PDF, so that I can place it in my new PDF?

Posted on StackOverflow on Apr 11, 2014 by Andres Olarte

The most basic solution is to copy the pages from one pdf document to another which you are creating on the fly:

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest).setSmartMode(true));
PdfDocument srcDoc = new PdfDocument(new PdfReader(src));
srcDoc.copyPagesTo(1, srcDoc.getNumberOfPages(), pdfDoc);

Click this link if you want to see how to answer this question in iText 5.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now