Python 将 docx 转为 PDF

安装

pip install docx2pdf



使用

from docx2pdf import convert

# doc 文件 需要先转为 docx 文件(一般情况下、直接修改后缀名、不会对原文件有影响)
inputFile = '1.docx'  # 要转换的文件:已存在
outputFile = '1.pdf'  # 要生成的文件:不存在

# 先创建 不存在的 文件
f1 = open(outputFile, 'w')
f1.close()

# 再转换往PDF中写入内容
convert(inputFile, outputFile)

posted @ 2022-06-24 01:34  三个零  阅读(3360)  评论(0编辑  收藏  举报