用com.itextpdf.text.Document打印pdf报错
时间:2017-06-22 12:23:39,594 - 级别:[ERROR] - 消息: [other] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: com.itextpdf.text.pdf.PdfDiv.setKeepTogether(Z)V] with root cause - 位置:org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]:182
java.lang.NoSuchMethodError: com.itextpdf.text.pdf.PdfDiv.setKeepTogether(Z)V
at com.itextpdf.tool.xml.css.apply.DivCssApplier.apply(DivCssApplier.java:232)
at com.itextpdf.tool.xml.html.CssAppliersImpl.apply(CssAppliersImpl.java:115)
at com.itextpdf.tool.xml.html.CssAppliersImpl.apply(CssAppliersImpl.java:125)
at com.itextpdf.tool.xml.html.Div.end(Div.java:105)
at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:229)
at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:208)
at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:142)
at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:397)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:71)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:237)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:215)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:174)
导入的jar包版本不对不兼容,应该导入下面三个jar包
itextpdf-5.5.9.jar
itext-asian-5.2.0.jar
xmlworker-5.5.9.jar
maven
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.9</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.9</version>
</dependency>
gradle
compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.9'
compile group: 'com.itextpdf', name: 'itext-asian', version: '5.2.0'
compile group: 'com.itextpdf.tool', name: 'xmlworker', version: '5.5.9'