embed images as base64 instead of outputing to folder

旧城冷巷雨未停 提交于 2021-01-28 19:32:34

问题


When converting from docx to html you may specify the output path for any images

org.docx4j.Docx4J.toHTML(wordMLPackage, imageDirPath, imageTargetUri, fos2);

and the resulting html document references images via files:

<img height="22" id="rId7" src="..cc6bcedf-2770-45ad-8e81-610bbd8746ceimage1.png" width="42">

Instead I would like the converter to embed the files as base64. Is this possible?


回答1:


You can write your own ConversionImageHandler implementation to do that.

The default implementation HTMLConversionImageHandler writes images to files.

To use your image handler, specify it via htmlSettings.setImageHandler




回答2:


You do not need a custom ConversionImageHandler to achieve this. You can simply set imageDirPath to an empty string and the images will be embedded

org.docx4j.Docx4J.toHTML(wordMLPackage, "", "", fos2);

This occurs because org.docx4j.model.images.AbstractConversionImageHandler (from which HTMLConversionImageHandler derives) already handles this case for you .



来源:https://stackoverflow.com/questions/30794169/embed-images-as-base64-instead-of-outputing-to-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!