提问人:Алина Михалева 提问时间:5/25/2023 最后编辑:Алина Михалева 更新时间:5/25/2023 访问量:55
使用 docx4j 将 HTML 转换为 DOCX 后,图片在 LibreOffice 中不完全可见
Pictures not fully visible in LibreOffice after converting HTML to DOCX using docx4j
问:
我用docx4j将html转换为docx文件
我需要获取 docx 文档才能在 libreOffice 中打开。我创建了一个docx,但是在libreOffice中图片并不完全可见。如果我在属性中设置“将图像附加到符号” - 图片,图像将完全可见,但图片会向上移动。我如何做到这一点,穿刺将完全可见并留在原地。在word中图片显示正确,但我需要libreOffice
我用docx4j将html转换为docx文件
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
RFonts arialRFonts = Context.getWmlObjectFactory().createRFonts();
arialRFonts.setAscii(ReportAndTemplateManagementConstants.FONT_FAMILY);
arialRFonts.setHAnsi(ReportAndTemplateManagementConstants.FONT_FAMILY);
XHTMLImporterImpl.addFontMapping(ReportAndTemplateManagementConstants.FONT_FAMILY, arialRFonts);
XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
xhtmlImporter.setHyperlinkStyle("Hyperlink");
tempConvertFile =
File.createTempFile("tempConvertFile", StringPool.PERIOD + ReportAndTemplateManagementWebKeys.DOCX);
tempFileOutput =
File.createTempFile("tempFileOutput", StringPool.PERIOD + ReportAndTemplateManagementWebKeys.DOCX);
wordMLPackage.getMainDocumentPart().getContent()
.addAll(xhtmlImporter.convert(content, tempFileOutput.getAbsolutePath()));
wordMLPackage.save(tempConvertFile);
我在 src 中有带有 base64 的 img html 标签。我所有的html:
<!DOCTYPE html>
<html>
<p style="text-align: left; font-size: 12pt; font-family: Arial, sans-serif; margin-top: 0px; margin-bottom: 0px; line-height: 1.15; " ><strong>СПРАВКА</strong><br />демо<br />25.05.2023<br /><strong>_________________________________________________________________________</strong></p>
<p style="text-align: justify; font-size: 12pt; font-family: Arial, sans-serif; text-indent: 35.4pt; margin-top: 0px; margin-bottom: 0px; line-height: 1.15; " ><ins class="ice-ins ice-cts" data-changedata="" data-cid="2" data-last-change-time="1684999190829" data-time="1684999190829" data-userid="" data-username=""><img src="data:image/png;base64,iV...UVORK5CYII=" /></ins></p>
</html>
图像不完全可见:
UPD与解决方案: 我比较了文件中的两个xml,其中图片可见,而在图片不可见的文件中。我找到了一个解决方案。 图片可见:w:spacing w:lineRule=“auto” w:line=“276” w:before=“0” w:after=“0” />
图片不可见:w:spacing w:lineRule=“exact” w:line=“276” w:before=“0” w:after=“0” />
因此,我以这种方式将行规则设置为段落 https://stackoverflow.com/a/27752060/21688996
它正在工作!我看到了我的图像!
答: 暂无答案
评论