Answer is no longer necessary because I've found the solution by myself.
// Create a stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Open the AcroForm
PdfReader readerAcroForm = new PdfReader("pdf/acroform.pdf");
// Create a stamper
PdfStamper stamp = new PdfStamper(readerAcroForm, baos);
// Extract AcroFields
AcroFields form = stamp.getAcroFields();
// Fill in the fields
readerForm.setField("city", "PARIS");
readerForm.setField("country", "FRANCE");
// Flattening the fields
stamp.setFormFlattening(true);
// Close the stamper
stamp.close();
// Close the reader of the AcroForm
readerAcroForm.close();
// Read the filled AcroForm
readerAcroform = new PdfReader(baos.toByteArray());
// ...and extract the page
PdfImportedPage pageFilledAcroform =
writer.getImportedPage(readerAcroform, 1);
// Close the reader of the filled AcroForm
readerAcroform.close();
// Create a PDF document
Document document = new Document();
// Associate the document to the screen in order to write on it
PdfWriter writer = PdfWriter.getInstance(document,
response.getOutputStream());
// Open the PDF document
document.open();
// Get the stream
PdfContentByte cb = writer.getDirectContent();
// Open the static PDF
PdfReader readerStaticPdf = new PdfReader("pdf/staticpdf.pdf");
// Navigate through the static PDF
for(int i=1; i<=readerStaticPdf.getNumberOfPages(); i++){
document.newPage();
PdfImportedPage page = writer.getImportedPage(readerStaticPdf, i);
cb.addTemplate(page,0,0);
if (i==1 || i==3 || i==5){
cb.addTemplate(pageFilledAcroForm,0,0);
}
}
// Close the reader of the static PDF
readerStaticPdf.close();
// Free the document and display it to the screen
document.close();
Not really simple but very useful for those who want to mix static PDF and
AcroForms.
I hope that it could help anyone.
--
View this message in context:
http://www.nabble.com/Using-iText-for-merging-documents-tp14433512p14436733.html
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/