我正在尝试找到将 docx 文件转换为 XHTML 的解决方案。
我找到了 xdocreport,它看起来不错,但我有一些问题。(我是 xdocreport 的新手)
根据他们在 github 上的文档here和here:我应该能够使用此代码进行转换:
String source = args[0];
String dest = args[1];
// 1) Create options DOCX to XHTML to select well converter form the registry
Options options = Options.getFrom(DocumentKind.DOCX).to(ConverterTypeTo.XHTML);
// 2) Get the converter from the registry
IConverter converter = ConverterRegistry.getRegistry().getConverter(options);
// 3) Convert DOCX to (x)html
try {
InputStream in = new FileInputStream(new File(source));
OutputStream out = new FileOutputStream(new File(dest));
converter.convert(in, out, options);
} catch (XDocConverterException | FileNotFoundException e) {
e.printStackTrace();
}
我正在使用这些依赖项(尝试了不同的版本,如 2.0.2、2.0.0、1.0.6):
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.document.docx</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.template.freemarker</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.converter.docx.xwpf</artifactId>
<version>2.0.2</version>
</dependency>
我的问题:
- 图像丢失
- 缺少背景颜色(所有页面都有背景颜色,不是白色,我也必须转换它)
我该如何处理这些问题?(或者如何使用带有格式/编号/图像的 Docx4j 将 docx 转换为 xhtml?)