【问题标题】:Convert pdf to docx using Libre Office,an error occurs使用 Libre Office 将 pdf 转换为 docx,出现错误
【发布时间】:2018-02-14 09:40:27
【问题描述】:

我尝试用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

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

【问题讨论】:

  • 代码上写着--convert-to doc,但您正在转换为docx?看起来您没有发布实际使用的代码。另外,当您从命令行运行单个 lowriter 命令时是否会出现问题?也发布单个命令。
  • 谢谢!实际上我已经尝试过--convert-to doc 和'--convert-to docx',我一定已经发布了'doc'的代码和'docx'的错误消息。我的错误!我可以确定不是这个问题。正如你所建议的,我尝试在命令行中运行“lowriter”命令。发生同样的错误!

标签: python pdf docx libreoffice


【解决方案1】:

为 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)

【讨论】:

    猜你喜欢
    • 2013-07-30
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2017-08-17
    • 2018-10-02
    • 1970-01-01
    相关资源
    最近更新 更多