java 项目里 .docx文件转pdf格式 需要的jar为 jacob.jar
注意:使用jacob的包时候,需要把他的dll文件放到JDK和JRE的bin下边,然后把jar包放到项目里lib下,并build
@Test
public void demo6 () throws Exception {
String path = "C:\\Users\\lenovo\\Desktop\\文档1.docx";
String pathpdf = "C:\\Users\\lenovo\\Desktop\\文档2.pdf";
File file = new File(path);
if(file.exists()) {
ActiveXComponent activeXComponent = new ActiveXComponent("Word.Application");
Dispatch documents = activeXComponent.getProperty("Documents").toDispatch();
Dispatch document = Dispatch.call(documents, "Open", path, false, true).toDispatch();
Dispatch.call(document, "SaveAs", pathpdf, 17);
// 关闭文档
Dispatch.call(document, "Close", false);
}
}