OK this is as far as I've got so far. So far I'm only handling the front page
(HEADER) however the HEADER pdf form fields don't seem to be filled.
// First Pass - Create Content
Document document = new Document(PageSize.A4);
PdfWriter.getInstance(document, new FileOutputStream(CONTENT));
document.open();
Chapter chapter = new Chapter("Chapter", 1);
chapter.setBookmarkOpen(true);
chapter.add(new Paragraph("Chapter intro paragraph"));
Section section = chapter.addSection("Section", 0);
section.add(new Paragraph("Section paragraph"));
section.add(new Paragraph("Section paragraph"));
document.add(chapter);
document.close();
// Second Pass - Apply Header & Template (optional)
// Fill header fields
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader headerReader = new PdfReader(new RandomAccessFileOrArray(HEADER),
null);
PdfStamper stamper = new PdfStamper(headerReader, baos);
AcroFields form = stamper.getAcroFields();
Set<String> keys = new HashSet<String>(form.getFields().keySet());
for (String key : keys) {
form.setField(key, getStringValueFor(String key));
}
stamper.close();
// 1.2 Insert into final document
PdfReader contentReader = new PdfReader(new RandomAccessFileOrArray(CONTENT),
null);
headerReader = new PdfReader(baos.toByteArray());
stamper = new PdfStamper(contentReader, new FileOutputStream(RESULT));
PdfImportedPage page = stamper.getImportedPage(headerReader, 1);
stamper.insertPage(1, contentReader.getPageSize(1));
stamper.getOverContent(1).addTemplate(page, 0, 0);
stamper.close();
_____
From: Antony Webster [mailto:[email protected]]
To: [email protected]
Sent: Sun, 13 Feb 2011 21:09:42 +0100
Subject: [iText-questions] PDF Watermarks
Hi,
I'm trying to merge various pdfs while both keeping memory use and final file
size down. Here is my scenario.
I'm generating pdfs of approximately 90 pages. So far so good. However I'd like
to merge each page of my 'content' pdf with a 'template' pdf. This 'template'
pdf is like a 1 page watermark containing a header, a footer and possibly an
actual watermark. Additionally the header and footer will contain fields which
reference information about the context of the 'content' pdf (for instance
'author', 'date', 'company' etc..). These fields will be filled in upon
generation. They will stay the same for each page however the 'page number'
field obviously won't. It doesn't stop there. I'd also like to append a 'title
page' pdf to the final pdf file. Similarly this file with have fields which
shall be filled in upon generation.
Any help would be most appreciated...
Anthony ------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
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