Java 在Itext的XMLWorkerHelper类中找不到方法(parseToElementList(str,null))
我是iText新手,我想在iText中将HTML字符串转换为Pdf。我在网上找到了很多例子。然后我发现了一个示例,并希望在这里实现相同的示例,但无法在我的项目中实现该示例。 我在pom.XML文件中添加了依赖项 以下是链接: Pom.xmlJava 在Itext的XMLWorkerHelper类中找不到方法(parseToElementList(str,null)),java,maven,itext,pdf-generation,xmlworkerhelper,Java,Maven,Itext,Pdf Generation,Xmlworkerhelper,我是iText新手,我想在iText中将HTML字符串转换为Pdf。我在网上找到了很多例子。然后我发现了一个示例,并希望在这里实现相同的示例,但无法在我的项目中实现该示例。 我在pom.XML文件中添加了依赖项 以下是链接: Pom.xml <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf --> <dependency> <groupId>com.itextp
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.0.6</version>
</dependency>
**<!-- https://mvnrepository.com/artifact/com.itextpdf.tool/xmlworker -->
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.4.1</version>
</dependency>**
安装maven命令后,上面的parseToElementList(str,null)
方法不可用
任何人都可以给我这个XMLWorkerHelper类的maven依赖项,它包含parseToElementList(str,null)
方法
谢谢
Sitansu如果您是iText新手,那么您不应该从这样一个旧版本开始。您应该从当前版本开始:iText 7.1.1+PDFHTML2.0.1。使用该版本,您只需要以下代码:
public static void main() throws IOException {
// IO File htmlSource = new File("input.html");
File pdfDest = new File("output.pdf");
// pdfHTML specific code
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
}
更多信息、教程、下载等,请访问我在@AxelHIn添加了代码在您使用的示例中,注释中有重复的URL(因为示例是从该帖子创建的)。在回答评论部分。您可以看到该方法是在版本5.5中添加的。4@AxelH感谢分享您使用的iText版本5.0.6和XMLWorker 5.4.1;这很糟糕,版本应该匹配。正如@AxelH所说,该方法已在5.5.4版中引入;因此,毫无疑问,这种方法是缺失的。因此,将您的依赖项更新为当前的匹配版本。好的,因此我将这个问题作为一个重复问题关闭为一组三个问题:显示所需的版本,是关于匹配的版本,以及更一般的关于应该使用什么来代替。
public static void main() throws IOException {
// IO File htmlSource = new File("input.html");
File pdfDest = new File("output.pdf");
// pdfHTML specific code
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
}