package cn.com.sparknet.index.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
public class Demo {
public static void main(String[] args) {
doc2pdf("/home/upload/公司网站提交测试单.doc","/home/upload/公司网站提交测试单.pdf");
}
public static void doc2pdf(String inPath, String outPath) {
FileOutputStream os =null;
try {
File file = new File(outPath); // 新建一个空白pdf文档
os = new FileOutputStream(file);
Document doc = new Document(inPath); // Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(os!=null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
参考word转pdf路径:https://www.jb51.net/article/171084.htm
需要到的两个jar包:
<dependency>
<groupId>com.aspose.words</groupId>
<artifactId>aspose-words</artifactId>
<version>14.9.0-jdk16</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>