首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OCRmyPDF无输出

OCRmyPDF无输出
EN

Stack Overflow用户
提问于 2021-01-05 16:05:27
回答 1查看 703关注 0票数 1

我正在使用OCRmyPDF从扫描的pdf文件中提取文本。为此,我使用了this Colab notebook中的代码。唯一的区别是,我不是从在线url下载pdf文件,而是使用存储在本地计算机上的pdf文件(将其替换为{file_name}而不是{invoice_pdf})。到我运行的时候,一切看起来都很好:

代码语言:javascript
复制
os.system(f'ocrmypdf {file_name} output.pdf')

而不是0,我得到了512!下一行,当我运行!ocrmypdf Performance Evaluations.pdf output.pdf时,我得到一条无法识别的错误消息,如下所示:

代码语言:javascript
复制
usage: ocrmypdf [-h] [-l LANGUAGE] [--image-dpi DPI]
                [--output-type {pdfa,pdf,pdfa-1,pdfa-2}] [--sidecar [FILE]]
                [--version] [-j N] [-q] [-v [VERBOSE]] [--title TITLE]
                [--author AUTHOR] [--subject SUBJECT] [--keywords KEYWORDS]
                [-r] [--remove-background] [-d] [-c] [-i] [--oversample DPI]
                [-f] [-s] [--skip-big MPixels] [--max-image-mpixels MPixels]
                [--tesseract-config CFG] [--tesseract-pagesegmode PSM]
                [--tesseract-oem MODE]
                [--pdf-renderer {auto,tesseract,hocr,sandwich}]
                [--tesseract-timeout SECONDS]
                [--rotate-pages-threshold CONFIDENCE]
                [--pdfa-image-compression {auto,jpeg,lossless}]
                [--user-words FILE] [--user-patterns FILE] [--skip-repair]
                [-k] [-g] [--flowchart FLOWCHART]
                input_pdf_or_image output_pdf
ocrmypdf: error: unrecognized arguments: output.pdf

最后,运行以下代码行:

代码语言:javascript
复制
with pdfplumber.open('output.pdf') as pdf:
    page = pdf.pages[0]
    text = page.extract_text(x_tolerance=2)
    print(text)

返回

代码语言:javascript
复制
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-19-8274f7005856> in <module>()
----> 1 with pdfplumber.open('output.pdf') as pdf:
      2     page = pdf.pages[0]
      3     text = page.extract_text(x_tolerance=2)
      4     print(text)

/usr/local/lib/python3.6/dist-packages/pdfplumber/pdf.py in open(cls, path_or_fp, **kwargs)
     56     def open(cls, path_or_fp, **kwargs):
     57         if isinstance(path_or_fp, (str, pathlib.Path)):
---> 58             fp = open(path_or_fp, "rb")
     59             inst = cls(fp, **kwargs)
     60             inst.close = fp.close

FileNotFoundError: [Errno 2] No such file or directory: 'output.pdf'

任何帮助都是非常感谢的。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-05 16:18:53

如果文件名包含空格,则需要用引号将名称括起来。

代码语言:javascript
复制
ocrmypdf "Performance Evaluations.pdf" output.pdf

代码语言:javascript
复制
ocrmypdf 'Performance Evaluations.pdf' output.pdf
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65575093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档