使用 Python 将 PDF 转换为 .docx

新手上路,请多包涵

我正在努力寻找 使用 Python 将 PDF 文件转换为 .docx 文件的 方法。

我看过与此相关的其他帖子,但在我的案例中,它们似乎都无法正常工作。

我是专门用

import os
import subprocess

for top, dirs, files in os.walk('/my/pdf/folder'):
    for filename in files:
        if filename.endswith('.pdf'):
            abspath = os.path.join(top, filename)
            subprocess.call('lowriter --invisible --convert-to doc "{}"'
                            .format(abspath), shell=True)

这给了我输出 [1],但是,我在我的文件夹中找不到任何 .docx 文档。

我安装了 LibreOffice 5.3。

有什么线索吗?

先感谢您!

原文由 Also 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 643
1 个回答

我将它用于多个文件

####
from pdf2docx import Converter
import os

# # # dir_path for input reading and output files & a for loop # # #

path_input = '/pdftodocx/input/'
path_output = '/pdftodocx/output/'

for file in os.listdir(path_input):
    cv = Converter(path_input+file)
    cv.convert(path_output+file+'.docx', start=0, end=None)
    cv.close()
    print(file)

原文由 simon 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题