Search code examples
javapdfitextxmlworker

exception during convert html to pdf using itext


i am trying to convert my html to pdf file in java using itext.i am using eclipse editor,i have add two jar file

     xmlworker-5.4.3.jar, 
     itextpdf-5.1.0.jar

in classpath.my code is given beloow

        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new 
        FileOutputStream("pdf.pdf"));
        document.open();
        XMLWorkerHelper.getInstance().parseXHtml(writer, document,new  
        FileInputStream("index.html"));
        System.out.println( "PDF Created!" );

when i run above code it gives me exception. i don't know how to solve it. my exception is given below

        Exception in thread "main" java.lang.NoSuchMethodError:  
        com.itextpdf.text.log.LoggerFactory.getLogger(Ljava/lang/Class;)Lcom/itextpdf
        /text/log/Loger;
        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 om.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:213)
        at df.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:185)
        at com.ps.App.main(App.java:47)

i think my error will at this place

   XMLWorkerHelper.getInstance().parseXHtml(writer, document,new  
        FileInputStream("index.html"));

Help me hove to solve this exception..... Thanks in advance.


Solution

  • It seems versions of these jars are not compatible with each other. Try below versions and let us know xmlworker-5.4.5.jar, itextpdf-5.4.5.jar