【发布时间】:2020-10-03 11:31:09
【问题描述】:
我想从我的 mac 打开一个 pdf 文件,但是我收到了这个错误:
'此文件无法打开。它可能已损坏或具有预览无法识别的文档结构。'
这是我正在使用的代码:
from docx import Document
#open the document
doc=Document('./testDoc.docx')
a = input('Whats your name ')
b = input('Whats your date of birth ')
Dictionary = {"name": a, "dob": b}
for i in Dictionary:
for p in doc.paragraphs:
if p.text.find(i)>=0:
p.text=p.text.replace(i,Dictionary[i])
#save changed document
doc.save('/my/path/contract{}.pdf'.format(a))
有人知道怎么回事吗?
【问题讨论】:
-
python-docx 无法导出为 pdf。你可以试试this
标签: python pdf docx converters