pom
xml
<!-- word -> pdf -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.0.3</version>
</dependency>
代码
java
@Test
public void pdf232() {
long l = System.currentTimeMillis();
String wordPath = "E:\\歌\\2022_江区_1716896947404\\日常\\2_取水户建月现场验.docx";
String pdfPath = "E:\\歌\\2022_江区_1716896947404\\日常\\2_水户中每月现验.pdf";
try {
System.out.println(wordPath + " 开始转换.....");
InputStream docxInputStream = new FileInputStream(wordPath);
OutputStream outputStream = new FileOutputStream(pdfPath);
IConverter converter = LocalConverter.builder().build();
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
outputStream.close();
long l2 = System.currentTimeMillis();
System.out.println(l2-l);
System.out.println(pdfPath + " 转换成功.....");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("导出成功......");
}