public static void word2Pdf(String wordPath,String pdfPath) {
if (getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
try {
File file = new File(pdfPath); // 新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
OsInfo osInfo = SystemUtil.getOsInfo();
if (osInfo.isLinux()) {
FontSettings.setFontsFolder("/usr/share/fonts/chinese",true);
}
Document doc = new Document(wordPath); // wordPath是将要被转化的word文档
doc.save(os,SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static boolean getLicense() {
try {
InputStream is = FileUtils.class.getClassLoader().getResourceAsStream("license.xml");
License license = new License();
license.setLicense(is);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
linux word转PDF
于 2023-07-18 17:51:44 首次发布