Hello,
I am trying to create a large PDF file containing all concatenated letters
to send to all subscribers.
Each letter has 2 pages, so the final PDF page count will be 2 x nb
subscribers.
The original letter is a PDF Form containing some fields. This fields are
then completed by the application, and once completed, the form is
flattened, then copied with PdfCopy in the final PDF file.
It work well, but the generated PDF is quite big, the process takes a long
time, and if I generate too much letters (a fex hundred), I have an
OutOfMemory...
Do I have to release some ressources ? Did I miss something ?
Code :
public void run() {
try {
Document document = new Document();
// final generated PDF
PdfCopy writer = new PdfCopy(document, new
FileOutputStream("result_good.pdf"));
document.open();
for (int i = 0; i < NB_SUBSCRIBERS; i++) {
// original PDF Form
RandomAccessFileOrArray pdf0 = new
RandomAccessFileOrArray("pdf3.pdf");
PdfReader reader0 = new PdfReader(pdf0, null);
// fill form fields
ByteArrayOutputStream baos0 = new ByteArrayOutputStream();
PdfStamper stamper0 = new PdfStamper(reader0, baos0);
AcroFields form0 = stamper0.getAcroFields();
form0.setField("name", "Mael_"+i);
form0.setField("year", ""+(2009+i));
form0.setField("number", ""+(i+1));
form0.setField("v1", "v1_"+(i+1));
form0.setField("v2", "v2_"+(i+1));
form0.setField("var2", "var2_"+(i+1));
form0.setField("bigField", "text..."+(i+1));
// flattening the form
stamper0.setFormFlattening(true);
stamper0.close();
reader0.close();
PdfReader reader01 = new PdfReader(baos0.toByteArray());
// copy flattened form in the final PDF (page 1 and page 2)
writer.addPage(writer.getImportedPage(reader01, 1));
writer.addPage(writer.getImportedPage(reader01, 2));
writer.flush();
}
document.close();
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
--
View this message in context:
http://old.nabble.com/OutOfMemory-while-creating-large-files-with-PdfCopy-tp27016141p27016141.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
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/