Hi,

Here is the problem I need to solve:

I have a list of byte arrays which represents list of files. I need to
combine them into one pdf. They can be pdf, images, or information I
need to put into the new pdf.

I cannot use PdfWriter because some pdfs contain not just content but
annotations according to this post:
http://itext-general.2136553.n4.nabble.com/Followup-Some-content-not-copied-when-concatenating-PDFs-td2163908.html

So, I have to use PdfCopy. It works fine for any byte array which
represents pdf file. But for image files, I don't know how to put them
in. Here is what I came out but I kept getting
"PDF header signature not found." error:

Document itextDoc = new Document(PageSize.LETTER, 0, 0, 0, 0);
PdfCopy pdfCopy = new PdfCopy(itextDoc, fos);
FileOutputStream fos = new FileOutputStream(fileName);

// problem happens here because nothing is in pdfCopy yet.
PdfReader reader = new PdfReader(pdfCopy.getDirectContent().toPdf(pdfCopy));
itextDoc.open();


Image image =Image.getInstance(r.getData()); // get byte array data of
an image (say, png)
itextDoc.setMargins(10, 10, 10, 10);
image.scaleToFit(ITEXT_PDF_WIDTH - 20, ITEXT_PDF_HEIGHT - 20);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
PdfContentByte content = stamper.getOverContent(reader.getNumberOfPages());
content.addImage(image);
stamper.close();

reader = new PdfReader(baos.toByteArray());
pdfCopy.addPage(pdfCopy.getImportedPage(reader, 1));
pdfCopy.freeReader(reader);
baos.close();

Has anyone done this process before?

Thanks!

-MK

------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to