aj2patte wrote: > Hello, > > I'm trying to add a dynamically generated cover page, along with a > header/footer, to existing PDFs and I need some help. What I would like to > do is: > > 1. Create an in memory Document with one or more pages with some text on > them (Cover page).
OK, use a ByteArrayOutputStream that holds the bytes of that PDF. > 2. Open an existing PDF document. OK, do this with PdfReader. > 3. Take each page of the existing PDF document and append it to the in > memory document while adding header/footer text to each appended page. Why? That doesn't seem like a good idea. Wouldn't it be better to open the existing PDF with PdfStamper? You can use insertPage to add a new front page and add the header and footer as described in the book. > 4. Write out the newly created in memory document to file. Same as 1. use a ByteArrayOutputStream instead of a FileOutputStream. > Obviously I'm an itext nube... I have deleted your pseudo code example as it might give other iText newbies bad thoughts. You made mistakes that are almost unforgivable ;-) No seriously. With all the examples that are available online, I feel a little bit insulted that there are still people who copy pages using byte[] b = reader.getPageContent(i); It's like swearing in the Church. > if anyone has some suggestions or pointers I'd > appreciate it. http://1t3xt.info/examples/browse/?page=example&id=24 over = stamper.getOverContent(i); over.beginText(); over.setFontAndSize(bf, 18); over.setTextMatrix(30, 30); over.showText("page " + i); over.endText(); (Or use showTextAligned instead of setTextMatrix + showText) http://1t3xt.info/examples/browse/?page=example&id=26 stamper.insertPage(1, PageSize.A4); For more examples: http://1t3xt.info/examples/browse/ -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php
