1

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?

chluebke
  • 11
  • 2
  • 4
  • 1
    This looks like "dirty XMP". Can you share the PDFs – Bruno Lowagie May 23 '14 at 14:01
  • @BrunoLowagie Files are available: [File 1](http://www.kurvas.de/temp/g7701.pdf) [File 2](http://www.kurvas.de/temp/g7701-2.pdf) Two versions of the same file, created with different PDF generators. – chluebke May 26 '14 at 06:11
  • 1
    Hmm... I couldn't reproduce the problem, but I notice something in your error message: do you by any chance have two different iText versions in your CLASSPATH? – Bruno Lowagie May 26 '14 at 07:48
  • No, I haven't. But you hint led me to the right direction. I have an older version of Apache Xerces in the classpath which causes the error. I'll have to look if I can safely replace it by the current one which looks fine on first view. Thank's alot! – chluebke May 27 '14 at 09:31
  • That's good news! That probably explains the `AbstractMethodError`. – Bruno Lowagie May 27 '14 at 09:49

2 Answers2

3

We had the same problem in our project, where we used FOP for generating PDF and iText for PDF signing.

FOP has a dependency on the xercesImpl:xerces jar. This jar is important for JRE <= 1.4 but it isn't needed in the JRE>1.4 and works without it (more information on JDK 1.6 and Xerces?).

Ps: Check that you do not have the xerces library on classpath, if so remove it.

Community
  • 1
  • 1
0

I had the same problem (with xerces), I could fix it by adding an exclusion in my dependency:

    <dependency>
        <groupId>net.sf.barcode4j</groupId>
        <artifactId>barcode4j-fop-ext-complete</artifactId>
        <version>2.0</version>
        <type>jar</type>
        <exclusions>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Nihal
  • 5,262
  • 7
  • 23
  • 41