I am new to itext7, I am using Elcipse 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?
Thanks,
I think you have forgot to add SL4j Library or jar into your project.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.