Java 无法导入HTMLConverter

Java 无法导入HTMLConverter,java,pdf,intellij-idea,itext,itext7,Java,Pdf,Intellij Idea,Itext,Itext7,我有一个现有的Java项目,我需要在其中创建一个PDF。我需要HTMLConvertor将HTML转换为PDF,然后使用PDFReader和PDFStamper将内容添加到各个字段(getAcroFields) 因此,我使用iText 5.5.12,无法导入HTMLConverter。 此版本不支持它吗? 我找不到有关发布的文档。 我尝试了以下方法,但没有成功。我试图从Maven中将iText7添加为一个新库,但5.5.12之前的版本都可用 我是Intellij新手,那么如何安装iText,支持

我有一个现有的Java项目,我需要在其中创建一个PDF。我需要HTMLConvertor将HTML转换为PDF,然后使用PDFReader和PDFStamper将内容添加到各个字段(getAcroFields)

因此,我使用iText 5.5.12,无法导入HTMLConverter。 此版本不支持它吗? 我找不到有关发布的文档。 我尝试了以下方法,但没有成功。我试图从Maven中将iText7添加为一个新库,但5.5.12之前的版本都可用

我是Intellij新手,那么如何安装iText,支持HTMLConverter的版本呢

提前谢谢

你写:

我试图从Maven中将iText7添加为一个新库,但5.5.12之前的版本都可用

这是错误的。请参阅iText网站上的安装说明:

复制POM文件中的粘贴:

<dependencies>

    <!-- always needed -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>kernel</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- always needed -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>io</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- always needed -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>layout</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for forms -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>forms</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for PDF/A -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>pdfa</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for digital signatures -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>sign</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for barcodes -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>barcodes</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for Asian fonts -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>font-asian</artifactId>
        <version>7.0.4</version>
    </dependency>

    <!-- only needed for hyphenation -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>hyph</artifactId>
        <version>7.0.4</version>
    </dependency>

</dependencies>

com.itextpdf
内核
7.0.4
com.itextpdf
木卫一
7.0.4
com.itextpdf
布局
7.0.4
com.itextpdf
形式
7.0.4
com.itextpdf
pdfa
7.0.4
com.itextpdf
签名
7.0.4
com.itextpdf
条形码
7.0.4
com.itextpdf
亚洲字体
7.0.4
com.itextpdf
连字符
7.0.4
要能够使用pdfHTML附加组件,您需要添加以下内容:

<repositories>
  <repository>
    <id>itext</id>
    <name>iText Repository - releases</name>
    <url>https://repo.itextsupport.com/releases</url>
  </repository>
</repositories>

文字
iText存储库-发布
https://repo.itextsupport.com/releases
这是暂时的,因为目前pdfHTML是封闭源代码的,不在Maven Central上,但它很快就会成为开放源代码,在接下来的几周内

您需要pdfHTML的许可证密钥(30天试用或购买),然后将其添加到POM中:

<dependencies>


  <!-- pdfHTML -->
  <dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>html2pdf</artifactId>
    <version>2.1.3</version>
  </dependency>

  <!-- iText 7 License Key Library -->
  <dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-licensekey</artifactId>
    <version>2.0.4</version>
  </dependency>

</dependencies>

com.itextpdf
html2pdf
2.1.3
com.itextpdf
itext licensekey
2.0.4

HtmlConverter类是iText 7的一个附加组件。它与iText 5不兼容。事实上,iText是从头重写的,以使
HtmlConverter
成为可能。有关历史概述,请参阅:

2016年,我们发布了iText 7,这是iText的一个全新版本 与以前的版本不再兼容,但这是使用 pdfHTML在脑海中。在新的渲染器上花费了大量的工作 框架当使用iText 7创建文档时,一个 生成渲染器及其子渲染器。布局是由创建的 遍历该树,这种方法在 处理HTML到PDF的转换。iText对象被完全删除 重新设计以更好地匹配HTML标记,并允许设置样式 CSS方式。”

您可以按照下载说明下载iText 7:

至于第一个版本,是在对太多第三方开发人员不忠于iText开发人员这一事实进行了长时间的争论之后,在封闭源代码中开发的。他们假装不知道,在作为封闭源代码软件分发(作为二进制或SaaS上下文)的应用程序中,通常不能免费使用AGPL软件。决定关闭一些附加组件的源代码,以提高知名度,并避免我们不得不起诉(请参阅中的幻灯片8至62)


与此同时,我们已经获得了使pdfHTML开源(AGPL)的批准,但在新版本发布之前需要几周时间。同时,您可以在购买许可证之前注册以获取许可证。

是否有其他方法可以读取HTML模板、向字段添加值和呈现PDF?我可以使用XMLWorkerHelper吗?这个明智的答案:暗示了一种方法。请帮帮我,我就是搞不懂。看看这个。您可以使用XML Worker,但是(1.)它没有pdfHTML那么完整,(2.)您希望获得对它的支持(而且似乎您需要支持),以及(3.)它也以AGPL的形式发布,因此如果您在商业环境中使用它,您可能需要商业许可证。既然您是iText的新手,为什么您会故意选择使用旧版本???那没什么意义,是吗?