我创建了一些脚本来编辑Word文档。我想要将其另存为pdf文件。如果我将'docx'放在pdf当前所在的位置,则一切正常。但是,如果我这样尝试,则无法通过finder在Macbook上打开它,因为它说:
'无法打开该文件。可能已损坏或具有预览无法识别的文档结构。'
这是我正在使用的代码:
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))
有人知道我能做什么,以便程序自动将其另存为我可以打开的pdf文件吗?