添加maven依賴
<dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc</artifactId> <version>2.2.0</version> </dependency>
轉換代碼如下
String fromFile = "E:/test.docx"; String toFile = "E:/test.pdf"; Document document = new Document(); document.loadFromFile(fromFile); document.saveToFile(toFile, FileFormat.PDF);
注:免費版有文件大小限制,可以替換成正式版,但是正式版有版權提示如下,內容不受影響
Evaluation Warning: The document was created with Spire.Doc for JAVA.
經測試,新版本只能打印10頁,且每頁都有水印,舊版本2.2.0可正常使用
下面方法可完美刪除版權信息
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.5.11</version> </dependency>