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;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微笑点燃希望

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值