使用Libre Office将pdf转换为docx,发生错误

时间:2017-09-06 02:53:03

标签: python pdf docx libreoffice

我尝试使用Libreoffice将pdf转换为docx,并使用Convert PDF to DOC (Python/Bash) 提供的此方法,代码如下:

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)

然而,当我调试它时,我收到一个错误:

Error: source file could not be loaded
Error: no export filter for C:\Users\owner\desktop\docx\my.docx found, aborting.
Error: no export filter

我已经使用Google搜索了一段时间,但是我的问题没有任何答案。所以我在这里寻求帮助。 非常感谢!

1 个答案:

答案 0 :(得分:0)

为 pdf 提供导出过滤器以在您的目录中搜索文件...

例如:

subprocess.call('lowriter --invisible --convert-to doc:writer_pdf_export "{}"' .format(abspath), shell=True)

subprocess.call('lowriter --invisible --convert-to doc:draw_pdf_export "{}"' .format(abspath), shell=True)