一、使用jscob插件
1、引入jacob.jar
2、在JRE中添加jacob-1.19-x64.dll或者jacob-1.19-x86.dll
3、运行代码
import java.io.File;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
public class test {
public static void main(String[] args) {
String word = "D:/sss.docx";
String name = "zhukaixin".concat(".pdf");
String pdf = "D:\\" + name;
wToPdfChange(word, pdf);
}
public static void wToPdfChange(String wordFile, String pdfFile) {// wordFile word 的路径 //pdfFile pdf 的路径
ActiveXComponent app = null;
System.out.println("开始转换...");
// 开始时间
// long start = System.currentTimeMillis();
try {
// 打开word
app = new ActiveXComponent("Word.Application");
// 获得word中所有打开的文档
Dispatch documents = app.getProperty("Documents").toDispatch();
System.out.println("打开文件: " + wordFile);
// 打开文档
Di