I am using iText (specifically iTextSharp 4.1.6) and I want to create a PDF by combining pages from existing PDFs but also inserting new pages created from an image.
I have got these two parts working separately using PdfCopy and PdfWriter respectively. The code to create a page from an image looks like this:
PdfWriter pw = PdfWriter.GetInstance(doc, outputStream);
Image img = Image.GetInstance(inputStream);
doc.Add(img);
doc.NewPage();
Now, Since PdfCopy inherits from PdfWriter, I thought I would be able to add such "image pages" to my PdfCopy object using the same technique, but it doesn't work (if you instantiate a PdfCopy instead of a PdfWriter in the above example, nothing comes out on the page).
From a quick peek at the source code I notice that when the contstructor for PdfCopy calls the superclass constructor it does so with a new Document object, not the one passed in, so I guess this is the reason.
Is there a better way to go about this? At the moment my best guess is to create a single page Pdf from the image using PdfWriter and then add it to the document using PdfCopy, but that seems like a bit of a workaround.