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?
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 How to reuse a page from one PDF document into another PDF document? if you want to see how to answer this question in iText 5.