Silvia wrote:
Hello everybody, I want create a pdf file to strt from a pdf file model,
What do you mean by file model?
A PDF with an AcroForm?
I set
the fields of this model and create the new file,
OK. You fill in the fields of the AcroForm with PdfStamper.
but now I want compile the
model more than one time with different values and obtain a single pdf file with
multiple page one for a different compilation of the model.
You copy everything with PdfCopy.
Hoe can I do this?
PdfReader reader = new PdfReader("HelloWorldLetter.pdf");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields form = stamper.getAcroFields();
form.setField("field", "World,");
stamper.setFormFlattening(true);
stamper.close();
reader = new PdfReader(baos.toByteArray());
Document document = new Document(reader.getPageSizeWithRotation(1));
PdfCopy writer = new PdfCopy(document,
new FileOutputStream("HelloWorldStampCopy.pdf"));
document.open();
writer.addPage(writer.getImportedPage(reader, 1));
reader = new PdfReader("HelloWorldLetter.pdf");
baos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, baos);
form = stamper.getAcroFields();
form.setField("field", "People,");
stamper.setFormFlattening(true);
stamper.close();
reader = new PdfReader(baos.toByteArray());
writer.addPage(writer.getImportedPage(reader, 1));
document.close();
Of course you'll have to write a loop or two.
One so that you don't have to copy/paste the read/stamp/copy code.
Another one to copy every page of the original PDF, not just the first one.
br,
Bruno
PS:
Ah, what fun it is when you are writing a book.
You finally make the time to write some damn good examples ;-)
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions