mammoth 模块,可以将 docx 文件转为 html,可以清理掉 html 代码中 word 的一些特定格式.也能输出 docx 文件中的图片.
在 windows 的 cmd 下,使用如下命令:
mammoth document.docx --output-dir=output-dir
则在 output-dir 目录下,输出 html 文件和图片文件.
如下 Python 代码:
with open("document.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value # The generated HTML
messages = result.messages```
以上代码会生成 html 代码,并不能将 docx 中的图片保存到一个目录里边;
同时在 html 中,图片会被使用 base64 编码,并且删除了 width 和 height 属性.
我想要的是,将图片保留到一个目录里边;
同时生成的 html 代码里,不要将图片使用 base64 编码,并保持图片的 width 和 height 属性.
英文太差,看得头痛也没有搞清楚怎么弄,请大家帮助,最好贴下简单的代码,多谢您的回复!