安装pip install -i https://pypi.doubanio.com/simple/ python-docx
工程结构如下:
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from pdf2docx import Converter
from loguru import logger
# 获取到当前路径
path = os.getcwd()
# 获取到当前所有为pdf的文件
def get_filelist():
Filelist = []
for home, dirs, files in os.walk(path):
for filename in files:
# 文件名列表,包含完整路径
if ".pdf" in filename:
# print(filename)
Filelist.append(os.path.join(home, filename))
else:
pass
return Filelist
def main():
Filelist = get_filelist()
for file in Filelist:
pdf_file = file
docx_file = ".".join(pdf_file.split(".")[:-1]) + ".docx"