java - 使用 docx4j 将 HTML 字符串转换为 docx 图像未嵌入 docx
问题描述
我有带有图像 base64 的 HTML 字符串,想转换成 DOCX。我正在使用 AlternativeFormatInputPart 进行转换。如果我使用 XHTMLImporterImpl 那么我在 HTML 中面临格式化问题。
String html = "<html><body><p>Hello Docx4j</p> <p> <img src="data:image/png;base64,iVBORw0KGgoAAA..." alt=""/> </p> </body></html>";
htmlToDocx(html, wordMLPackage);
private void htmlToDocx(String htmlString, WordprocessingMLPackage wordMLPackage) throws Exception {
AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw.html"));
afiPart.setContentType(new ContentType("text/html"));
afiPart.setBinaryData(htmlString.getBytes());
Relationship altChunkRel = documentPart.addTargetPart(afiPart);
CTAltChunk chunk = factory.createCTAltChunk();
chunk.setId(altChunkRel.getId());
documentPart.addObject(chunk);
}
它在没有图像的情况下进行转换,如果我将提供图像路径而不是 base64,那么它将起作用,但我有多个图像在服务器(linux)上动态出现。如何使用 AlternativeFormatInputPart 嵌入图像。
请帮我添加base64图像。
提前致谢!
解决方案
推荐阅读
- flutter - 如何从另一个班级返回未来?
- linux - 如何使用cygwin
- java - 我想知道为什么 eclipse 和“oracle 数据库”之间的连接不起作用
- c# - 告诉我 OLEDB 数据阅读器读取 excel 文件列的最大限制是多少?
- python - 如何从我加载的 keras 模型中获取更多信息?
- java - 在数组中有效地查找子数组的算术平均值
- c# - 在代码中查找 Webview2 WPF 控件的 Edge 版本
- c# - 带有只读项的 ReadOnlyCollection
- android - 即使我的应用程序不存在于“最近”中,哪个是 android 中最好的时间调度程序?
- amp-html - AMP - 在 amp 页面中包含图标