Hi list,

I have 2 existing pdf files each containing text fields, an invoice form and a summary form

I need to generate a pdf file that consists of a number of invoices and one instance of the summary report. Each of the invoices has to be merged with invoice information from a database.

Now, I am able to generate one invoice by doing the following:

PdfReader reader = new PdfReader("invoiceForm.pdf");
PdfStamper stamp = new PdfStamper(reader, bos);
PdfContentByte contentByte = stamp.getOverContent(1);
            AcroFields form1 = stamp.getAcroFields();


            form1.setField("name", "Birthe Berland");
...
            stamp.setFormFlattening(true);
stamp.close();

How do I repeat this to generate a pdf file containing a number of invoices and how do I append the summary report to the end of the file? I know the number of invoices. I tried something like, but I am not sure it is the right approach.

ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader("invoiceForm.pdf");
Document document = null;
PdfCopy writer = null;

for (int i=0; i<invoiceCount; i++) {
if (i == 0) {
document = new Document(reader.getPageSizeWithRotation(1));
writer = new PdfCopy(document, bos);
document.open();
}
PdfImportedPage page = writer.getImportedPage(reader, 1);
writer.addPage(page);
PRAcroForm form = reader.getAcroForm();
if (form != null)
writer.copyAcroForm(reader);
}
document.close();

reader = new PdfReader(bos.toByteArray());
ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
PdfStamper stamp = new PdfStamper(reader, bos1);


for (int i=0; i<invoiceCount; i++) {
PdfContentByte contentByte = stamp.getOverContent(i+1);
AcroFields form1 = stamp.getAcroFields();


form1.setField("name", "Birthe Berland");
}
            stamp.setFormFlattening(true);
stamp.close();

I seems that I get a number of pages but they are all copies of the last invoice.

I appreciate any help.

Birthe
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to