package com.lly.demo.util; // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // import com.lly.demo.bean.DocUser; import com.spire.doc.FileFormat; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.converter.WordToHtmlConverter; import org.apache.poi.hwpf.usermodel.Picture; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import static java.lang.System.out; //word转html public class docTohtml { public static void main(String[] args) throws Exception { docxToHtml(); } public Boolean docTohtml(DocUser docUser) throws Exception { String sourceFileName = docUser.getDocname(); String targetFileName = docUser.getHtmlname(); String imagePathStr = "D:/doc2htmltest/image/"; Boolean secORfiled=true; HWPFDocument wordDocument = null; File file=new File(sourceFileName); FileInputStream fileInputStream = new FileInputStream(sourceFileName); String docxtodocSourceFileName = docUser.getDocname().substring(0,docUser.getDocname().length()-5)+".doc"; try { if(StringUtils.isNotBlank(sourceFileName)&&StringUtils.isNotBlank(targetFileName)){ if(sourceFileName.endsWith(".doc")){ if(file.exists()){ out.println("aaaaa11111"); wordDocument = new HWPFDocument(fileInputStream); out.println("aaaaa"); if (wordDocument != null) { WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); wordToHtmlConverter.setPicturesManager((a, b, suggestedName, d, e) -> { // convertFileToBase64() out.println(suggestedName); //返回图片路径 //return "image" + File.separator + suggestedName; //返回图片base64值 return "data:image/"+b.getExtension().toLowerCase()+";base64,"+new String(Base64.encodeBase64(a)); }); wordToHtmlConverter.processDocument(wordDocument); List
依赖:
4.0.0 com.example demo 0.0.1-SNAPSHOT demo demo 1.8 UTF-8 UTF-8 2.3.7.RELEASE org.springframework.boot spring-boot-starter-web org.projectlombok lombok 1.16.10 io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2 org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.apache.poi poi 3.14 org.apache.poi poi-examples 3.14 org.apache.poi poi-excelant 3.14 org.apache.poi poi-scratchpad 3.14 org.apache.poi poi-ooxml 3.14 org.apache.poi ooxml-schemas 1.3 org.apache.pdfbox pdfbox 2.0.9 fr.opensagres.xdocreport xdocreport 1.0.6 org.apache.xmlbeans xmlbeans 2.6.0 org.projectlombok lombok 1.16.10 org.springframework.boot spring-boot-dependencies ${spring-boot.version} pom import org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugin 2.3.7.RELEASE com.lly.demo.DemoApplication repackage repackage
导航样式:
body{background:#e6d8d8;text-align:center;}
div{width:100%;margin:0 auto;background:#ecdfdf;text-align:left;}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.aside {
width: 240px;
height: 100%;
position: fixed;
left: -240px;
top: 0px;
border-right: 1px solid #ccc;
-ms-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
.aside:hover{
left: 0;
}
.aside:hover + .article{
padding-left: 260px;
}
.nav-list{
width: 100%;
height: 100%;
overflow: auto;
padding: 10px 0px;
}
.nav-mark{
position: absolute;
right: -20px;
top: 50%;
z-index: 2;
height: 80px;
width: 20px;
margin-top: -40px;
background-color: #44a7ff;
box-shadow: 2px 0px 3px #eee;
border-radius: 0 40px 40px 0;
font-size: 12px;
text-align: center;
line-height: 24px;
padding-top: 16px;
color: #fff;
}
.nav {
display: block;
width: 100%;
height: 32px;
line-height: 32px;
font-size: 16px;
color: #333;
text-decoration: none;
padding-left: 20px;
}
.nav:hover {
background-color: #44a7ff;
color: #fff;
}
.grade2 {
text-indent: 1em;
}
.grade3 {
text-indent: 2em;
}