[英]Save doc file as pdf file using python
I want to save a doc file as pdf using python, I tried so many solution but I couldn't find the right one.我想使用 python 将文档文件另存为 pdf,我尝试了很多解决方案,但找不到合适的解决方案。
This is my code, I tried to make the output file as a pdf file but it didn't open.这是我的代码,我试图将 output 文件制作为 pdf 文件,但它没有打开。 Any help is highly appreciated:
非常感谢任何帮助:
def replace_string(filenameInput, filenameOutput):
doc = Document(filenameInput)
for p in doc.paragraphs:
for d in J['data']:
if p.text.find(d['variable']) >= 0:
p.text = p.text.replace(d['variable'], d['value'])
doc.save(filenameOutput)
replace_string('test.docx', 'test2.pdf')
import docx2pdf
def convert_file(filenameInput, filenameOutput):
docx2pdf.convert(filenameInput, filenameOutput)
convert_file('test.docx', 'test2.pdf')
There is a Python package called docx2pdf.有一个叫docx2pdf的Python package。 You can use it to simply convert docx file into pdf!
您可以使用它简单地将 docx 文件转换为 pdf!
There is a link to the package!有包链接! https://pypi.org/project/docx2pdf/
https://pypi.org/project/docx2pdf/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.