Error while generating pdf from Html file in Java

2019-09-06 02:45发布

问题:

I am converting XML -> HTML -> pdf. The HTML -> pdf step is done with iText v5.5.3, but I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError: com.itextpdf.text.pdf.PdfPTable.addCell(Lcom/itextpdf/text/pdf/PdfPCell;)V
    at com.itextpdf.tool.xml.html.table.Table.end(Table.java:387)
    at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:155)
    at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:202)
    at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:140)
    at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:387)
    at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)
    at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:230)
    at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:209)
    at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:166)
    at ITextEx.createPdf(ITextEx.java:29)
    at ITextEx.main(ITextEx.java:41)

What am I missing?

回答1:

The html -> pdf conversion functionality is in a separate jar file, xmlworker-<version>.jar, but is still considered part of iText.

If you are using itextpdf-5.5.3.jar you should use xmlworker-5.5.3.jar.

Xmlworker is a part of the iText product and can be downloaded from the product web site.



标签: java itext