Our application generates a multiple page PDF by reading in a single page 
"template" PDF form, populating the form fields with values from the database, 
and adding a new page for each record from the database. The pattern is roughly:

    Document document = new Document();
   PdfCopy copy = new PdfCopy(document, new FileOutputStream(newFileName));
    document.open();
    PdfReader reader = new PdfReader(formFileName);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfStamper stamper = new PdfStamper(reader, baos);
    AcroFields form = stamper.getAcroFields();
    form.setField(fieldName, fieldValue);
    ...
    stamper.close();

Occasionally, calling stamper.close() results in the following 
FileNotFoundException:

java.io.FileNotFoundException: .\forms\template.pdf  (The system cannot find 
the path specified)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(Unknown Source)
at java.io.RandomAccessFile.<init>(Unknown Source)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.openForPlainRandomAccess( 
RandomAccessFileOrArray.java:172)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.openFile( 
RandomAccessFileOrArray.java:148)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.reOpen( 
RandomAccessFileOrArray.java:334)
at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2347)
at com.itextpdf.text.pdf.PRStream.toPdf(PRStream.java:215)
at com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)
at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:391)
at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:844)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:356)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:328)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:189)

I'm thinking that the template is still in use, and we are missing some 
required "cleanup" method call(s), but I find it strange that the error only 
occurs a small percentage of the time. Anyone else experience this?

-Peter Lachall

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to