I'm trying to fill PDF forms with data and got PDFStamper (itext version 5.5.1) to work with several PDF files, but on some it always fails. Sample code:
PdfReader reader = new PdfReader(new FileInputStream("C:/Temp/source.pdf"));
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("C:/Temp/temp.pdf"));
stamper.close();
Two different error messages until now, first one:
Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
at com.itextpdf.xmp.impl.XMPMetaParser.createDocumentBuilderFactory(XMPMetaParser.java:423)
at com.itextpdf.xmp.impl.XMPMetaParser.<clinit>(XMPMetaParser.java:71)
at com.itextpdf.xmp.XMPMetaFactory.parseFromBuffer(XMPMetaFactory.java:167)
at com.itextpdf.xmp.XMPMetaFactory.parseFromBuffer(XMPMetaFactory.java:153)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:337)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:208)
Second:
java.lang.reflect.InvocationTargetException
[...]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.itextpdf.xmp.impl.XMPMetaParser
at com.itextpdf.xmp.XMPMetaFactory.parseFromBuffer(XMPMetaFactory.java:167)
at com.itextpdf.xmp.XMPMetaFactory.parseFromBuffer(XMPMetaFactory.java:153)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:337)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:208)
The error messages vary, maybe because of different environments (full application vs. test class, but both using itext-5.5.1.jar).
One of the working PDF form was created using OpenOffice Writer, which produced a version 1.4 (Acrobat 5.x) document. The failing PDF form was created using Acrobat Distiller 7.0.5, pdf version 1.6 (Acrobat 7.x). I already tried to convert it down to version 1.4/5.x without luck.
Any ideas?