引入依賴
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
<!-- 此包據說收費,依賴不了 可以下載後 本地依賴 或直接引入jar 有的還需要修改配置文件 我用這個不用 -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.5</version>
</dependency>
代碼
String fileLocal = "D:/123.docx";
String pathPdf = "D:/123.pdf";
// 新建一個空白pdf文檔
File filePdf = new File(pathPdf);
//流轉換
FileOutputStream os = new FileOutputStream(filePdf);
// Address是將要被轉化的word文檔
Document doc = new Document(fileLocal);
// 全面支持DOC, DOCX, OOXML, RTF HTML
doc.save(os, SaveFormat.PDF);
//完成
注意
linux 可能存在字體缺失的情況,需要手動引入windows字體哦