如何使用 python 从 Word 文档中提取图像/徽标并将其存储在文件夹中。以下代码将 docx 转换为 html,但不会从 html 中提取图像。任何指示/建议都会有很大帮助。
profile_path = <file path>
result=mammoth.convert_to_html( profile_path)
f = open(profile_path, 'rb')
b = open(profile_html, 'wb')
document = mammoth.convert_to_html(f)
b.write(document.value.encode('utf8'))
f.close()
b.close()
您可以使用docx2txt库,它将读取您的 .docx 文档并将图像导出到您指定的目录(必须存在)。
!pip install docx2txt
import docx2txt
text = docx2txt.process("/path/your_word_doc.docx", '/home/example/img/')
执行后,您将获得图像/主页/示例/img/和变量text将有文档文本。它们将按出现顺序命名为 image1.png ... imageN.png。
注意:Word 文档必须为 .docx 格式。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)