将pdf转换为文本python错误



我想将pdf转换为指定目录下的文本

这是我试过的代码

import os
import subprocess
def pdftotext(pdf):
    # insert your code here
    basename, _ = os.path.splitext(os.path.basename(pdf))
    subprocess.call(['pdftotext', '-enc', 'UTF-8',
                 pdf, os.path.join('c:pdfpydfdata', basename + '.txt')])
pdftotext("C:\pdf\pydf\pdfs\ipm.pdf")
with open(os.path.join('c:\pdf\pydf\data', 'ipm.txt')) as infile:
   print(infile.read(1000))

但是它得到错误

Traceback (most recent call last):
File "C:/pdf/browser.py", line 10, in <module>
pdftotext("C:\pdf\pydf\pdfs\ipm.pdf")
File "C:/pdf/browser.py", line 8, in pdftotext
pdf, os.path.join('c:pdfpydfdata', basename + '.txt'), '-'])
File "C:Python34libsubprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:Python34libsubprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:Python34libsubprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我的代码有什么问题?

文件路径不正确,而不是C:pdfpydfpdfsipm.pdf useos.path。Join ('c:', 'pdf ', 'pdf ', 'ipm.pdf')

相关内容

  • 没有找到相关文章

最新更新