首先在pom里面引入依赖
<dependency>
<groupId>com.luhuiguo</groupId>
<artifactId>aspose-words</artifactId>
<version>23.1</version>
</dependency>
使用这个依赖,这个依赖已经是破解过的,不需要自己再破解一遍,接下来就是代码的编写了
public static boolean asposeWordToPdf(String inPath, String outputFilePath) {
FileOutputStream os = null;
try {
long old = System.currentTimeMillis();
File file = new File(outputFilePath); // 新建一个空白pdf文档
os = new FileOutputStream(file);
Document doc = new Document(inPath); // Address是将要被转化的word文档
//Linux 下使用字体库
// FontSettings fontSettings = new FontSettings();
// fontSettings.setFontsFolder("/usr/share/fonts/windows"+File.separator,true);
// doc.setFontSettings(fontSettings);
doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
// EPUB, XPS, SWF 相互转换
long now = System.currentTimeMillis();
System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); // 转化用时
} catch (Exception e) {
e.printStackTrace();
return false;
}finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
然后就可以实现word转pdf了,且不需要破解