本来是用的Spire.Doc生成的word文件,想直接再保存pdf一份,但是Spire.Doc保存pdf商业版有水印,免费版只能保存3页。
只能找一个word转pdf的方法了
注意:这个依赖仅限安装了wps office 或者微软office的电脑
依赖
<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>
代码
try (
InputStream docxInputStream = new FileInputStream(filePath + ".docx");
OutputStream outputStream = new FileOutputStream(filePath + ".pdf")
) {
IConverter converter = LocalConverter.builder().build();
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
System.out.println("word to pdf success");
} catch (Exception e) {
e.printStackTrace();
}