首页 > 编程语言 >docx转html方案验证-支持latex,表格,图片(aspose)

docx转html方案验证-支持latex,表格,图片(aspose)

时间:2024-07-08 11:55:42浏览次数:11  
标签:latex docx aspose html words poi apache org

方案总结:

1:poi(html属性支持) 存在一个bug,对于table中的cell中既有文本又有图片的在转化后图片丢失

2:tika(主要是提取内容,转换出来的html不太好)

3.openoffice(依赖安装,转出的html不太好)

4. aspose(功能强大但是付费),但也可以免费使用,缺点:不支持扩展原因代码不是开源的

5.mammoth(对比poi缺少标签的属性比如颜色字体),这个不存在一个cell中既有文本又有图片的在转化后图片丢失的问题,对于样式这块支持扩展,样例很多

 

1.maven依赖

    <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-examples</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-excelant</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>ooxml-schemas</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>18.6</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aspose-words-18.6-jdk16.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-cells</artifactId>
            <version>8.5.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aspose-cells-8.5.2.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.9</version>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>xdocreport</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.cssbox</groupId>
            <artifactId>pdf2dom</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
        </dependency>

        <!-- Hutool工具类 -->
        <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.3.8</version>
        </dependency>

 

2.代码实现

2.1 wordBytes2HtmlFile方法

 public static File wordBytes2HtmlFile(byte[] wordBytes, String htmlFilePath) {
        try {
            log.info("实现`aspose-words`授权 -> 去掉头部水印");
            /*
              实现匹配文件授权 -> 去掉头部水印 `Evaluation Only. Created with Aspose.Words. Copyright 2003-2018 Aspose Pty Ltd.` |
                                          `Evaluation Only. Created with Aspose.Cells for Java. Copyright 2003 - 2020 Aspose Pty Ltd.`
             */
//            InputStream is = new ClassPathResource("license.xml").getInputStream();
            // 从当前类加载器中加载资源
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("license.xml");
            if (is != null) {
                License license = new License();
                license.setLicense(is);
            }
        } catch (Exception e) {
            log.error("《`aspose-words`授权》 失败: {}", e.getMessage());
        }
        // Load word document from disk.
        com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(wordBytes));
        // Save the document into MHTML.
        doc.save(htmlFilePath, SaveFormat.HTML);
        return new File(htmlFilePath);
    }

 

2.2 readBytes方法

    public static byte[] readBytes(String filePath) {
        return FileUtil.readBytes(filePath);
    }

 

2.3main方法

    public static void main(String[] args) {
//        word2HtmlFile("D:\\doc","JKLJLJLGJ.docx","JKLJLJLGJ.1111.html");

        File htmlFile = wordBytes2HtmlFile(readBytes("D:\\doc\\xxxx.docx"),
                "D:\\doc\\xxxxxxxaaaa.html");

    }

 

标签:latex,docx,aspose,html,words,poi,apache,org
From: https://www.cnblogs.com/QAZLIU/p/18284031

相关文章

  • docx转html方案验证-支持latex,表格,图片(poi)
    方案总结:1:poi(html属性支持)存在一个bug,对于table中的cell中既有文本又有图片的在转化后图片丢失2:tika(主要是提取内容,转换出来的html不太好)3.openoffice(依赖安装,转出的html不太好)4.aspose(功能强大但是付费),但也可以免费使用,缺点:不支持扩展原因代码不是开源的5.mamm......
  • md文件批量转html
    1.requirements.txtbeautifulsoup4==4.12.3Markdown==3.62.main.pyimportmarkdownimportosimportshutilfrombs4importBeautifulSoupimportuuidimportargparsedefmd2html(src_folder,dest_folder):foriteminos.listdir(src_folder):......
  • 前端JS特效第19集:HTML5鼠标跟随星星光标特效
    HTML5鼠标跟随星星光标特效,先来看看效果:部分核心的代码如下(全部代码在文章末尾):<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml">......
  • 前端JS特效第20集:HTML5图片瀑布流带筛选功能代码
    HTML5图片瀑布流带筛选功能代码,先来看看效果:部分核心的代码如下(全部代码在文章末尾):<!DOCTYPEhtml><htmllang="en"class="no-js"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,init......
  • 前端JS特效第21集:HTML5响应式多种切换效果轮播大图切换js特效代码
    HTML5响应式多种切换效果轮播大图切换js特效代码,先来看看效果:部分核心的代码如下(全部代码在文章末尾):<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999......
  • 前端JS特效第22集:html5音乐旋律自定义交互特效
    html5音乐旋律自定义交互特效,先来看看效果:部分核心的代码如下(全部代码在文章末尾):<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>ChimeTime™</title><linkrel="stylesheet"href="css/style.css......
  • html入门
    1.HTML是什么HTML是什么:即HyperTextMarkuplanguage超文本标记语言,作用是定义网页的内容和结构。2.HTML元素HTML是由一系列元素组成。如:<p>Hello</P>元素可以有属性,如:<pid="p1">Hello</p>元素之间可以嵌套,如:<p>Hello<b>Wolrd</b><......
  • 关于web 第一章 初识HTML以及HTML四大案例 (保姆级教学)
    什么是HTML?HTML是用来描述网页的一种语言。HTML指的是超文本标记语言(Hyper Text Markup Language)HTML不是一种编程语言,而是一种标记语言 (markuplanguage)标记语言是一套标记标签 (markuptag)HTML使用标记标签来描述网页HTML标签HTML标记标签通常被称为H......
  • 前端HTML+CSS
    一、HTML1.什么是html概念:超文本标记性语言(HyperTextMarkupLanguage)--不只是有文本的标签超:超级文本===》不仅仅是普通文本还可以是:文字、图形、动画、声音、表格等。标记性:标记,元素,标签来源:w3c万维网联盟:组织java开源jspython2.作用:制作网页①网页应该......
  • 前端JS特效第15集:HTML5电脑端微信聊天窗口界面
    HTML5电脑端微信聊天窗口界面,先来看看效果:部分核心的代码如下(全部代码在文章末尾):<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1"><......