JAVA实现Word、rtf等转PDF
https://repository.aspose.com/repo/
下载
aspose-words-jdk16-14.6.0.0.jar
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = BTest.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void docToPdf(String inPath, String outPath) {
/*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
} */
try {
File file = new File(outPath); // 新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(inPath); // inPath是将要被转化的文档地址
doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,// EPUB, XPS, SWF 相互转换
} catch (Exception e) {
e.printStackTrace();
}
}