我想从我的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))有人知道哪里出了问题吗?
发布于 2020-06-14 14:24:10
docx模块无法将word文档转换为PDF。
您可以使用pywin32模块。
import win32com.client
def wordToPdf(input_path, output_path):
word = win32com.client.Dispatch("Word.Application")
doc = word.Documents.Open(str(input_path))
doc.SaveAs(str(output_path), FileFormat=17)
doc.Close()
word.Quit()https://stackoverflow.com/questions/62364757
复制相似问题