javahtml转docx(包含图⽚处理)1.引⼊jar包
<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>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>
2.部分代码
byte [] bytes = ("D://word.html"));
Document document = jsoup.parse(new String(bytes));
Elements imgs = ElementsByTag("img");
for (Element im : imgs){
String src = img.attr("src");
//图⽚转base64
img.attr("src", encodeBase64File(src));
}
/
/读取html⽂件返回btye数组
byte[] by= document.outerhtml().getBytes("UTF-8");
//初始化
init();
//创建Document
com.aspoe.words.Document doc = new com.aspoe.words.Document();
DocumentBuilder dbuilder= new DocumentBuilder(doc);
dbuilder.insertHtml(new String(by));
//保存docx
doc.save("D://word.docx", SaveFormat.DOCX);
/**
* 初始化,去除⽔印
*/
public static void init() {
try {
InputStream is = new ClassPathResource("l").getInputStream();
License license = new License();
license.setLicense(is);
} catch (Exception e) {
e.printStackTrace();
}
}
>java修改html文件
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论