java XMLWorkerHelper - NoSuchMethodError:com.itextpdf.text.pdf.PdfPTable.addCell

时间:2014-12-12 05:49:40

标签: java html pdf nosuchmethoderror itextpdf

我正在尝试使用itextpdf将html转换为pdf 但即使我使用最新版本的itextpdf

,它也给了nosuchmethoderror

依赖

    <dependency>
        <groupId>com.itextpdf.tool</groupId>
        <artifactId>xmlworker</artifactId>
        <version>5.5.3</version>
    </dependency>

进口

   import com.itextpdf.text.Document;
   import com.itextpdf.text.DocumentException;
   import com.itextpdf.text.pdf.PdfWriter;
   import com.itextpdf.tool.xml.XMLWorkerHelper;

   ....

来源

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/test.pdf"));
    document.open();
    String file = "/home/test.html";
    XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(file));  /* **line 191** */
    document.close();

例外

Exception in thread "main" java.lang.NoSuchMethodError: com.itextpdf.text.pdf.PdfPTable.addCell(Lcom/itextpdf/text/pdf/PdfPCell;)Lcom/itextpdf/text/pdf/PdfPCell;
    at com.itextpdf.tool.xml.html.table.Table.end(Table.java:433)
    at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:192)
    at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:207)
    at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:142)
    at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:396)
    at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:71)
    at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:236)
    at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:214)
    at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:175)
    at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:220)
    at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:182)
    at com.jvr.util.CommonUtil.pdf(CommonUtil.java:191)

1 个答案:

答案 0 :(得分:1)

我遇到了这个问题..

使用的com.itextpdf版本不正确

正确的版本是,

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.4.2</version>
    </dependency>