1.pdf转word
pdf2docx的下载:pip install pdf2docx -i https://pypi.tuna.tsinghua.edu.cn/simple
from pdf2docx import Converter #pdf转word a = Converter(r'D:PycharmCompanywork_test2.pdf') #pdf的路径 #输出的word的路径加文件名,不用自己创建,会自动创建,可将pdf路径直接复制下来,将后缀pdf改为docx就可以了。 a.convert(r'D:PycharmCompanywork_test2.docx') a.close() #一定要有,释放内存用的
2.单个word转pdf
docx2pdf 的下载:pip install docx2pdf -i https://pypi.tuna.tsinghua.edu.cn/simple
from docx2pdf import convert
# 第一个为word路径,第二个为生成的pdf路径,不用自己创建,会自动创建,可将docx路径直接复制下来,将后缀docx改为pdf就可以了
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/'
# 定义空list,存放文件夹中的文件名
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') #创建生成的pdf文件和文件名的文件名
print(file+'转换成功')



