0

I am new to itext7, I am using Eclipse IDE. I downloaded all the itext7 jar files and added it to my libraries (classpath). When I run my program (to convert text file to PDF file), I got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.itextpdf.kernel.pdf.PdfPagesTree.<clinit>(PdfPagesTree.java:72)
at com.itextpdf.kernel.pdf.PdfCatalog.<init>(PdfCatalog.java:99)
at com.itextpdf.kernel.pdf.PdfCatalog.<init>(PdfCatalog.java:103)
at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1958)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:284)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:265)
at TextFileToPDF.createPdf(TextFileToPDF.java:59)
at TextFileToPDF.main(TextFileToPDF.java:84)
`Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more

If I add all the jar files to my libraries(ModulePath), then I got the following errors:

Error: Unable to initialize main class TextFileToPDF Caused by: java.lang.NoClassDefFoundError: com/itextpdf/layout/element/IBlockElement

Does anybody knows how to fix this problem?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user7087799
  • 73
  • 1
  • 9
  • 2
    "Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory" -> you don't have slf4j in your classpath. But can't you just use Maven? That will resolve all dependencies automatically. – Amedee Van Gasse Feb 04 '21 at 10:30
  • I added the jar file from https://mvnrepository.com/artifact/org.slf4j/slf4j-api/2.0.6 which you can find under Files. Just download it and add it to your libs folder or wherever you have the jar files. – pabloberm Dec 15 '22 at 19:32

2 Answers2

1

I think you have forgot to add SL4j Library or jar into your project.

Thakkar Darshan
  • 350
  • 1
  • 15
0

It turns out that it missed the following 3 jars : slf4j.api, slf4j-log4j12, and log4j

It works now after adding the above 3 jars.

user7087799
  • 73
  • 1
  • 9