【问题标题】:Convert pdf files to docx in python [closed]在python中将pdf文件转换为docx [关闭]
【发布时间】:2021-07-30 04:27:46
【问题描述】:

我正在开发一个 python 项目,但作为项目的一部分,我正在尝试制作一个输入 pdf 文件和输出(docx 文件或文本)的 python 文件,反之亦然。 另外,如果可能的话,我会支持将 pdf 转换为 jpg 和 jpg 转换为 pdf。 我该怎么做 有没有人可以帮助我?

【问题讨论】:

  • 到目前为止您尝试过什么?你遇到了什么问题?
  • 请注意,StackOverflow 上已经有几个同样懒惰的问题有答案,您应该先查看并尝试,然后再毫不费力地再次提出相同的问题 stackoverflow.com/questions/57778665/… 或 stackoverflow.com/questions/56559796/convert-pdf-to-docx - 答案因为这类问题往往不被接受,只是因为提问者懒得去阅读或接受,如果你努力,我们会
  • 你好我的朋友@Grismar 试过 pypdf 但是当我提取测试它返回空行。我试过 slate 但它不起作用,因为 exeption 说没有安装一些东西。我试过 texttract 它也没有用。最后我尝试了docxtopdf,但它返回了这个异常:pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
  • 另外,这个问题将帮助很多人在短时间内以最好、简单和有保证的方式解决这个问题
  • @ZieadShabKalih 有教程可以帮助这样的人。您的问题与堆栈溢出无关

标签: python python-3.x file pdf converters


【解决方案1】:

pip install pdf2docx https://pypi.org/project/pdf2docx/

选项1

from pdf2docx import Converter
pdf_file = '/path/to/sample.pdf'
docx_file = 'path/to/sample.docx'
# convert pdf to docx
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()

选项2

from pdf2docx import parse
pdf_file = '/path/to/sample.pdf'
docx_file = 'path/to/sample.docx'
# convert pdf to docx
parse(pdf_file, docx_file, start=0, end=None)

【讨论】:

    猜你喜欢
    • 2019-10-26
    • 2021-10-03
    • 2013-11-02
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2010-12-02
    • 2018-10-02
    • 2017-04-14
    相关资源
    最近更新 更多