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 create a
PdfReader instance and to import the page into the
from which point on you can use the
PdfImportedPage instance, either directly, or wrapped inside an
PdfReader reader = new PdfReader(existingPdf); PdfImportedPage page = writer.getImportedPage(reader, i); PdfImage img = Image.getInstance(page); reader.close();