ekoz / kbase-doc

文档在线预览编辑,文档水印 / Office files preview or edit online, doc/docx convert to html, watermark
Apache License 2.0
470 stars 120 forks source link

word to pdf #4

Closed Ritian-Zhang closed 5 years ago

Ritian-Zhang commented 5 years ago

有木有word转pdf的

ekoz commented 5 years ago

核心转换时调用jodconverter,targetFile 后缀以.pdf结尾,转换后的目标文件就是 pdf 格式

protected void convert(File originFile, File targetFile) {
    WebappContext webappContext = WebappContext.get(servletContext);
    OfficeDocumentConverter converter = webappContext.getDocumentConverter();
    try {
            long startTime = System.currentTimeMillis();
            converter.convert(originFile, targetFile);
            long conversionTime = System.currentTimeMillis() - startTime;
            log.info(String.format("successful conversion: %s [%db] to %s in %dms",         FilenameUtils.getExtension(originFile.getName()), originFile.length(), FilenameUtils.getExtension(targetFile.getName()), conversionTime));
        } catch (Exception e) {
            e.printStackTrace();
            log.error(String.format("failed conversion: %s [%db] to %s; %s; input file: %s", FilenameUtils.getExtension(originFile.getName()), originFile.length(), FilenameUtils.getExtension(targetFile.getName()), e, targetFile.getName()));
        }
}