【问题标题】:Method (parseToElementList(str,null)) not found in XMLWorkerHelper class for Itext [duplicate]在 Itext 的 XMLWorkerHelper 类中找不到方法(parseToElementList(str,null))[重复]
【发布时间】:2018-07-17 08:42:34
【问题描述】:

我是 iText 的新手,我想在 Itext 中将 HTML 字符串转换为 Pdf。我在网上找到了很多例子。然后我找到了一个示例并想在这里实现相同的示例,但无法在我的项目中实现该示例。 我在 pom.XML 文件中添加了依赖项。

这是链接:

https://developers.itextpdf.com/examples/xml-worker-itext5/basic-html-examples

Pom.xml

<!-- 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>**

代码sn-p:

                PdfPTable table = new PdfPTable(1);
                PdfPCell cell = new PdfPCell();
                ElementList list =XMLWorkerHelper.parseToElementList(encountersoapnotes.getHpi(), null);
                for (Element element : list) {
                    cell.addElement(element);
                }
                table.addCell(cell);
                document.add(table);

上述parseToElementList(str,null)方法安装maven命令后不可用。

任何人都可以给我这个 XMLWorkerHelper 类的 maven 依赖项,它包含 parseToElementList(str,null) 方法。

谢谢 司坦苏

【问题讨论】:

  • 我现在添加了代码@AxelH
  • 在您使用的示例中,评论中有重复的 URL(因为该示例是从该帖子创建的)。在答案 cmets 部分。可以看到该方法是在5.5.4版本中添加的
  • @AxelH 感谢分享
  • 您使用 iText 版本 5.0.6 和 XMLWorker 5.4.1;这很糟糕,版本应该匹配。正如@AxelH 所说,该方法已在版本 5.5.4 中引入;所以难怪缺少该方法。因此,将您的依赖项更新为当前的匹配版本。
  • 好的,所以我把这个问题作为重复的三个问题结束了:Brunos answer to "Adding PdfDiv to Paragraph" and comment 显示所需的版本,Bruno's comment to "XML worker using itext" 是关于匹配版本,"Converting HTML to PDF using iText" 是关于应该做什么更笼统改为使用。

标签: java maven itext pdf-generation xmlworkerhelper


【解决方案1】:

如果您是 iText 的新手,那么您不应该从这么旧的版本开始。您应该从当前版本开始:iText 7.1.1 + pdfHTML 2.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);
}

更多信息、教程、下载等,请访问https://itextpdf.com/itext7/pdfHTML

【讨论】:

    猜你喜欢
    • 2019-02-02
    • 1970-01-01
    • 2013-02-07
    • 2017-05-22
    • 1970-01-01
    • 2015-04-20
    • 2013-06-25
    • 1970-01-01
    • 2016-03-20
    相关资源
    最近更新 更多