1.pdf转word pdf2docx的下载:pip install pdf2docx -i https://pypi.tuna.tsinghua.edu.cn/simple
from pdf2docx import Converter
a = Converter(r'D:\Pycharm\Company\work_test\2.pdf')
a.convert(r'D:\Pycharm\Company\work_test\2.docx')
a.close()
2.单个word转pdf docx2pdf 的下载:pip install docx2pdf -i https://pypi.tuna.tsinghua.edu.cn/simple
from docx2pdf import convert
convert("D:/Pycharm/Company/work_test/output.docx", "D:/Pycharm/Company/work_test/output.pdf")
3.多个word转多个pdf
from docx2pdf import convert
import os
path = 'D:/Pycharm/Company/work_test/'
files = []
for file in os.listdir(path):
if file.endswith(".docx"):
files.append(path+file)
for file in files:
convert(file,file.split('.')[0]+'.pdf')
print(file+'转换成功')
|