I migrate data from HTML document pages to docx via docx4j, basically everything else is working fine and normal images and contents are getting added in docx perfectly but in rare cases for long images the image isn't breaking at page break and the image is getting underlap hence the remaining image part is not visible.
and this is how it looks after HTML data and image is migrated to docx word via docx4j:
and this is how I add my HTML data to docx via docx4j:
XHTMLImporter = new XHTMLImporterImpl(template);
xhtmlSubTitleData=htmlToXhtml(subTitleData)
if(xhtmlSubTitleData.contains(" ")){
xhtmlSubTitleData=addNBSPDTDInSubTitleData(xhtmlSubTitleData)
}
template.getMainDocumentPart().getContent().addAll(pIndex+1,XHTMLImporter.convert( xhtmlSubTitleData, null))
Basically I am appending data in existing docx template but the long image isn't breaking at page break and because of that I am having data loss as missing part of image is not visible. I convert all the HTML in a HTML document page section into XHTML(xhtmlSubTitleData) and add it via addAll(), it works perfectly for everything else.
What should I do that can break long images like this automatically at page breaks without any data loss in such a way that remaining part is visible in next page or maybe resize it automatically to fit in the page in case the image is too long to fit in one?