无法在笔记本电脑上打开使用Python创建的pdf文件

问题描述 投票:0回答:1

我创建了一些脚本来编辑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文件吗?

python pdf docx converters
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.