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
  • 90,369
  • 161
  • 124
  • 175
  • 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

2 Answers2

0

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

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.