Hi,

I have a working piece of code that does the following:

1. Read a PDF and fill out the form fields.
2. Create a new document from scratch
3. Read a fix PDF
4. Concatenate the 3 pages and save to file.

I don't want to save anything to file but the resulting PDF.
I'd like to know if there a any big mistakes. What could be done 
in a better way.

Thanx and greetings
Frank


// Loading first PDF with form fields into baosFirstPage
FileInputStream fisFirstPage = new FileInputStream(SRC_FILE_1);
ByteArrayOutputStream baosFirstPage = new ByteArrayOutputStream();
PdfReader readerFirstPage = new PdfReader(fisFirstPage, null);
PdfStamper stamperFirstPage = new PdfStamper(readerFirstPage,
baosFirstPage);
stamperFirstPage.setFormFlattening(true);
AcroFields form = stamperFirstPage.getAcroFields();
// Filling form fields
setFields(form);
stamperFirstPage.close();

// Building 2nd page from scratch into baosProducts
Document document = new Document();
ByteArrayOutputStream baosProducts = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baosProducts);
document.open();
document.add(new Paragraph("Products"));
document.close();

// Loading lastPage into baosLastPage
FileInputStream fisLastPage = new FileInputStream(SRC_FILE_2);
ByteArrayOutputStream baosLastPage = new ByteArrayOutputStream();
PdfReader readerLastPage = new PdfReader(fisLastPage, null);
PdfStamper stamperLastPage = new PdfStamper(readerLastPage,
baosLastPage);
stamperLastPage.close();

// Concatenating the 3 byte array streams into baosResult;
ByteArrayOutputStream baosResult = new ByteArrayOutputStream();
PdfCopyFields copy = new PdfCopyFields(baosResult);
copy.addDocument(new PdfReader(baosFirstPage.toByteArray()));
copy.addDocument(new PdfReader(baosProducts.toByteArray()));
copy.addDocument(new PdfReader(baosLastPage.toByteArray()));
copy.close();

// Write result to file
PdfReader readerResult = new PdfReader(baosResult.toByteArray());
PdfStamper stamperResult = new PdfStamper(readerResult, new
FileOutputStream(DST_FILE));
stamperResult.close();

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to