导入所需的包pdf2docx
from pdf2docx import Converter
自定义函式名pdf2word(file_path)
def pdf2word(file_path):
file_name = file_path.split('.')[0]
doc_file = f'{file_name}.docx'
p2w = Converter(file_path)
p2w.convert(doc_file, start=0, end=None)
p2w.close()
return doc_file
输出转换的word文件
#file_path是需要转换的pdf文件的路径
pdf2word('E:/learn/PDF文件转换为WORD文件.pdf')