pdf - iText Error: java.io.IOException: trailer not found -


i'm creating web application fill pdf form using itext. create pdf forms i'm first using microsoft word create template, saving it, opening file in adobe acrobat xi pro, adding form fields, , saving pdf. problem pdf not saving trailer when execute this:

pdfreader reader = new pdfreader(templatename); 

it throws exception "java.io.ioexception: trailer not found". know can read pdf if has trailer because i've tried reading other pdfs. appears issue acrobat not adding trailer pdf. if try creating pdf form scratch in acrobat not saved trailer.

has else run problem? there setting in acrobat add trailer? there way itext read without trailer?

====update====

i must have had old version of itext because when downloaded latest version able read pdf file. after reading file , stamping got exception closing stamper. code looks this:

pdfreader reader = new pdfreader(templatename); fileoutputstream os = new fileoutputstream(outputpath); pdfstamper stamper = new pdfstamper(reader, os); acrofields acrofields = stamper.getacrofields();  list<string> fields = getfieldnames(getcontextcd()); (string field : fields) {     acrofields.setfield (field, stringutil.checkempty(request.getparameter(field))); }  stamper.setformflattening(true); stamper.close(); 

the error got was:

java.lang.abstractmethoderror: javax.xml.parsers.documentbuilderfactory.setfeature(ljava/lang/string;z)v @ com.itextpdf.xmp.impl.xmpmetaparser.createdocumentbuilderfactory(xmpmetaparser.java:423) @ com.itextpdf.xmp.impl.xmpmetaparser.(xmpmetaparser.java:71) @ com.itextpdf.xmp.xmpmetafactory.parsefrombuffer(xmpmetafactory.java:167) @ com.itextpdf.xmp.xmpmetafactory.parsefrombuffer(xmpmetafactory.java:153) @ com.itextpdf.text.pdf.pdfstamperimp.close(pdfstamperimp.java:337) @ com.itextpdf.text.pdf.pdfstamper.close(pdfstamper.java:208)

the jar file added classpath itextpdf-5.5.2.jar. need of other jars?

my solution work... assumption 1: pdf missing trailer, placed under resources/xxx , after build moved classess/xxx assumption 2: trying read pdf classpath , trying make pdfreader object pdf file path.

if above assumptions right, below solution followed reasoning: go pom file or ever build configuration file have, , change setting exclude .pdf files being filtered during build. want pdf move resources/xxx classess/xxx without manipulation build activities. below:

<build>         <resources>           <resource>             <directory>src/main/resources</directory>             <filtering>true</filtering>             <excludes>                 **<exclude>**/*.pdf</exclude>**             </excludes>           </resource>         </resources> 

explanation needed? ok. when resources being moved resources/xxx classess/xxx, no matter kind of file are, interpreted build process. while doing pdf, trailer , eof tags expected. if not, build tool adds characters pdf content report problem code trying use pdf. if skip filtering of pdf build activity, same pdf work if trailer missing.

hope helps!


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -