zoukankan      html  css  js  c++  java
  • apose word 导出html

        public static Boolean wordTwoHtmlTemp(String wordPath, String outputHtmlPath) {
            if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
                return false;
            }
            try {
                long old = System.currentTimeMillis();
                File file = new File(outputHtmlPath); //新建一个空白pdf文档
                FileOutputStream os = new FileOutputStream(file);
                Document doc = new Document(wordPath); //Address是将要被转化的word文档
                HtmlSaveOptions saveOptions = new HtmlSaveOptions();
                saveOptions.setCssStyleSheetType(CssStyleSheetType.INLINE);
                //指定是将字体资源导出到HTML,MHTML还是EPUB。默认值为false。
                saveOptions.setFontsFolderAlias("font");
                saveOptions.setFontSavingCallback(fontSavingArgs -> fontSavingArgs.getFontStream());
                //指定是否应使用Base64编码将字体资源嵌入HTML。默认值为false。
                saveOptions.setExportImagesAsBase64(true);
                //指定页面设置是导出到HTML,MHTML还是EPUB。默认值为false。
                saveOptions.setExportPageSetup(true);
                //指定在保存到HTML,MHTML或EPUB时是否应以相对单位输出字体大小。默认值为false。
                saveOptions.setExportRelativeFontSize(true);
                //控制文本输入表单字段如何保存到HTML或MHTML。默认值为false。
                saveOptions.setExportTextInputFormFieldAsText(true);
                //如果为true,则在适用的情况下输出漂亮的格式。默认值为false。
                saveOptions.setPrettyFormat(true);
                //获取或设置一个值,该值确定是否使用高质量(即慢速)渲染算法。(继承自SaveOptions)
                saveOptions.setUseHighQualityRendering(true);
                saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
                saveOptions.setSaveFormat(SaveFormat.HTML);
                saveOptions.setExportPageMargins(true);
    //            saveOptions.setTableWidthOutputMode(HtmlElementSizeOutputMode.RELATIVE_ONLY);
                for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)) {
                    run.getFont().setName("FZYaSongS-DB-GB");
                }
                saveOptions.setExportDocumentProperties(true);
    //            Drawing
                doc.acceptAllRevisions();
                doc.save(os, saveOptions);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
                long now = System.currentTimeMillis();
                logger.info("AposeUtil wordTwoHtml wordPath={}  htmlPath={} program time consuming={}",
                        wordPath, outputHtmlPath, ((now - old) / 1000.0) + "秒");
                return true;
            } catch (Exception ex) {
                logger.info("AposeUtil wordTwoHtml ex={}", ex.toString());
                return false;
            }
        }

  • 相关阅读:
    第二阶段冲刺第四天
    第二阶段冲刺第三天
    第二阶段冲刺第二天
    第二阶段冲刺第一天
    软件工程结对作业01(补充)
    软件工程概论个人总结
    梦断代码阅读笔记06
    梦断代码阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记01
  • 原文地址:https://www.cnblogs.com/lykbk/p/4564e554545drtfdtgdtdrtdrtdrtrdtrtrtrtrtrtrt.html
Copyright © 2011-2022 走看看