maven导入依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.4.3</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>6.0.0</version>
</dependency>
需要在resource目录添加simsun.ttc字库文件以支持Linux系统转换中文字体
编写Java代码
/**
* Word转Pdf
* @param wordPath Word文件位置
* @param pdfPath 导出的PDF文件位置
* @return 导出的PDF文件位置
*/
public static String convertDocx2Pdf(String wordPath,String pdfPath) {
OutputStream os = null;
InputStream is = null;
try {
is = Files.newInputStream(new File(wordPath).toPath())