Reputation: 313
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?
Upvotes: 0
Views: 168
Reputation: 15878
With docx4j-ImportXHTML, you can specify an implementation of the XHTMLImageHandler interface (using setXHTMLImageHandler).
If you don't do that, XHTMLImageHandlerDefault will be used. That code uses createImageInline. It does contain logic for scaling wide images, but not long ones.
If experimentally I paste your image into a paragraph in a Word docx, it does lay it out onto a new page.
I can't see right now any relevant difference in the XML. So its not clear what any altered XHTMLImageHandler would do differently.
So to pursue this further I'd need to see your docx. Feel free to open an issue and attach it at https://github.com/plutext/docx4j-ImportXHTML/issues
Upvotes: 0