I convert html to docx file with docx4j
I need to get docx document for opening in libreOffice. I create a docx, but in libreOffice pictures don't visible fully. If I set in properties "attach an image to a symbol" - picture the image becomes fully visible, but the picture moves up. How i can do that pucture will be visible fully and stay on its place. In word pictures show correctly, but I need libreOffice
I convert html to docx file with docx4j
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);
I have img html tag with base64 in src. All my 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>
Image not fully visible:
UPD with solution: I compare two xml in file, where picture is visible and in file where picture is not visible. I have found a solution. Picture is visible: w:spacing w:lineRule="auto" w:line="276" w:before="0" w:after="0" />
Picture is not visible: w:spacing w:lineRule="exact" w:line="276" w:before="0" w:after="0" />
so, I set Line rule to paragraphs in such way https://stackoverflow.com/a/27752060/21688996
And It is working! I see my images!
