使用docx4j将html字符串转换为docx图像未嵌入docx中

x759pob2  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(259)

我有html字符串与图像base64和想转换成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图像。
提前谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题