linux word转PDF
/ 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换。// wordPath是将要被转化的word文档。if (getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生。
·
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;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)