0

I have HTML file which i'm tring to convert into pdf using iTextPdf but I'm getting following error,

java.lang.NoSuchMethodError: 
com.itextpdf.text.log.LoggerFactory.getLogger(Ljava/lang/Class;)
Lcom/itextpdf/text/log/Logger;

the lib are as follows

  • itextpdf-5.4.5.jar
  • xmlworker-5.4.5.jar
  • slf4j-api-1.7.7.jar
  • slf4j-log4j12-1.7.7.jar

please guide me to solve this problem, thanks in advance

Edit :

  • itextpdf-5.5.2
  • itextpdf-5.5.2-javadoc
  • itextpdf-5.5.2-sources
  • itext-pdfa-5.5.2
  • itext-pdfa-5.5.2-javadoc
  • itext-pdfa-5.5.2-sources
  • itext-xtra-5.5.2
  • itext-xtra-5.5.2-javadoc
  • itext-xtra-5.5.2-sources

java.lang.NoSuchMethodError: com.itextpdf.text.log.LoggerFactory.getLogger(Ljava/lang/Class;)Lcom/itextpdf/text/log/Logger;
        at com.itextpdf.tool.xml.net.FileRetrieveImpl.<clinit>(FileRetrieveImpl.java:67)
        at com.itextpdf.tool.xml.css.StyleAttrCSSResolver.<init>(StyleAttrCSSResolver.java:113)
        at com.itextpdf.tool.xml.css.StyleAttrCSSResolver.<init>(StyleAttrCSSResolver.java:102)
        at com.itextpdf.tool.xml.css.StyleAttrCSSResolver.<init>(StyleAttrCSSResolver.java:90)
        at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:213)
        at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:185)

Class Path

    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-pdfa-5.5.2-javadoc.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-pdfa-5.5.2-sources.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-pdfa-5.5.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-xtra-5.5.2-javadoc.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-xtra-5.5.2-sources.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itext-xtra-5.5.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itextpdf-5.5.2-javadoc.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itextpdf-5.5.2-sources.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/itextpdf-5.5.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/xmlworker-5.5.2.jar"/>
user2582360
  • 55
  • 3
  • 13
  • That method is part of the core itextpdf library since at least version 5.1.1. Do you probably have another, older itextpdf library on your classpath? – mkl Sep 09 '14 at 06:58
  • 1
    Your edit looks like you use a fairly current xmlworker with an ancient itextpdf. Please do check whether there is a second itextpdf jar on your classpath. It looks like such a second jar is found before your current one and, therefore, is used. – mkl Sep 09 '14 at 08:50
  • @mkl i have added the XMLWorker with same version as iText Pdf, please check my edits, but still getting same exception – user2582360 Sep 09 '14 at 09:21
  • 1
    Are you sure your web application environment does not force an older itext version on you? E.g. using some endorsed libraries? You can try and test that by adding code right before your code running into that exception to create a simple PDF in the file system (e.g. using the method `createPdf` in [HelloWorld.java](http://itextpdf.com/examples/iia.php?id=12)). Inspecting the generated PDF file you can see the iText version which created the file. – mkl Sep 09 '14 at 09:29
  • @mkl solved, as you said it was loading ancient xmlworker, working fine after i clear the project. thank you so much, your comments helped me alot – user2582360 Sep 09 '14 at 09:30

1 Answers1

2

you have to also put following jar files in your lib.

  • itext-pdfa
  • itext-xtra

as per appropriate version. try to put whole required code.

Look into stack trance it may be refer to that class line where error was occur.

Hardik Visa
  • 323
  • 6
  • 23
  • 1
    Maybe, but the class and the "missing" method are in the core iText jar: https://sourceforge.net/p/itext/code/HEAD/tree/tags/iText_5_4_5/itext/src/main/java/com/itextpdf/text/log/LoggerFactory.java – Bruno Lowagie Sep 09 '14 at 06:31
  • I have added the jar files, but still i'm getting the same error, I have edited my question, please take a look. – user2582360 Sep 09 '14 at 08:29
  • did you check in com.itextpdf.text.log.LoggerFactory available or not ? if no then some problem about itextpdf jar file – Hardik Visa Sep 09 '14 at 09:07
  • @HArdik thank you for your answer, the xmlworker jar was not loading properly, working perfectly now :) – user2582360 Sep 09 '14 at 09:36