你寫:
我試圖iText的7添加從Maven的新庫,但版本5.5.12之前可用。
這是錯誤的。見iText的網站上安裝說明:在您的POM文件https://developers.itextpdf.com/itext7/download-and-install-information/Java
複製粘貼:
<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>
爲了能夠使用pdfHTML插件,你需要補充一點:
<repositories>
<repository>
<id>itext</id>
<name>iText Repository - releases</name>
<url>https://repo.itextsupport.com/releases</url>
</repository>
</repositories>
這是暫時的,因爲目前pdfHTML是封閉源代碼,而不是Maven Central,但在接下來的幾周內它將很快成爲開源代碼。
您將需要pdfHTML許可證密鑰,無論是30天試用或購買,然後添加到您的POM:
<dependencies>
<!-- pdfHTML -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>1.0.1</version>
</dependency>
<!-- iText 7 License Key Library -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-licensekey</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
有沒有其他方法可以讀取HTML模板,爲字段添加值並呈現PDF? 我可以使用XMLWorkerHelper嗎? 這個賢者的答案:https://stackoverflow.com/questions/35921388/how-to-convert-an-html-string-to-a-pdf-inputstream 建議一種方式。 請幫助,我只是無法弄清楚。 – raita
查看[歷史](https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml)。你可以使用XML Worker,但是(1)它不像pdfHTML那樣完整,(2)你想得到它的支持(它似乎你需要*支持),(3)它也被作爲AGPL發佈,所以如果您在商業環境中使用它,您可能還需要商業許可證。既然你是iText的* new *,爲什麼你會故意選擇使用舊版本?這沒有多大意義,是嗎? –