0

I am trying to create a PDF/A document using itext and java with the following code:

PdfAWrite writer = PdfAWriter.getInstance(myDoc, myStream, PdfAConformanceLevel.PDF_A_1A);

but I keep getting this exception:

java.lang.NoClassDefFoundError: com/itextpdf/text/log/CounterFactory
at com.itextpdf.text.pdf.PdfAWriter.<init>(PdfAWriter.java:210)
at com.itextpdf.text.pdf.PdfAWriter.getInstance(PdfAWriter.java:86)

this is my pom.xml

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.5.3</version>
</dependency>

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-pdfa</artifactId>
    <version>5.5.3</version>
</dependency>

can anyone tell what should I do to fix this problem?

Thanks

3 Answers 3

3

I get similiar exceptions when I have the said class in more than one jar. Maybe you should check your classpath for duplicates. Maybe different versions of the same library coexist. If you're using Eclipse, have a look at the 'Dependency hierarchy' view of the pom and try to locate a duplicate.

Sign up to request clarification or add additional context in comments.

2 Comments

That's a very good suggestion. The NoClassDefFoundError is often misleading in the sense that more than one version of the class if found, but the exact class can't be defined, because it's ambiguous: which version should be used? In any case: solving this should be a no-brainer. Plenty of people are using iText without experiencing this problem. Starting from scratch can always help.
@BrunoLowagie as you say the NoClassDefFoundError is misleading, the problem was that I had multiple dependecies in my pom.xml files. I solved the problem thanks to Kenneth's suggestion
1

Looks like you miss the itextpdf.jar in your classpath. Download the jar and add it to your classpath

10 Comments

I have that itextpdf-5.5.3.jar in my classpath along with the itext-pdfa-5.5.3.jar
@Shahe Can you show the classpath configuration? You are runing your app from IDE?
I am running my application from Eclipse IDE, and I am building my project with maven.
I am sorry, can you be more exact on what do you want me to show you? I don't know where the run configuration is.
@Shahe If you run your program from eclipse you use a launcher. You can see it under "Run"-->"Run Configurations". There you have a tab classpath. An the content of this should contain the jar as one entry.
|
0

The current release of Primefaces libraries refers to an older release of iText. If you try to install the latest iText distribution you will end up to the following error:

java.lang.NoClassDefFoundError: com/lowagie/text/

This is due to the fact that in the recent iText release the package com/lowagie/text has been renamed as com/itextpdf/text. So until this is fixed use the suggested iText release (2.1.7) or at least verify the package structure.

This might be useful: http://www.mastertheboss.com/jboss-web/primefaces/export-your-datatable-to-excel-and-pdf-using-primefaces?showall=&start=1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.