我正在使用OCRmyPDF从扫描的pdf文件中提取文本。为此,我使用了this Colab notebook中的代码。唯一的区别是,我不是从在线url下载pdf文件,而是使用存储在本地计算机上的pdf文件(将其替换为{file_name}而不是{invoice_pdf})。到我运行的时候,一切看起来都很好:
os.system(f'ocrmypdf {file_name} output.pdf')而不是0,我得到了512!下一行,当我运行!ocrmypdf Performance Evaluations.pdf output.pdf时,我得到一条无法识别的错误消息,如下所示:
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最后,运行以下代码行:
with pdfplumber.open('output.pdf') as pdf:
page = pdf.pages[0]
text = page.extract_text(x_tolerance=2)
print(text)返回
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'任何帮助都是非常感谢的。谢谢
发布于 2021-01-05 16:18:53
如果文件名包含空格,则需要用引号将名称括起来。
ocrmypdf "Performance Evaluations.pdf" output.pdf或
ocrmypdf 'Performance Evaluations.pdf' output.pdfhttps://stackoverflow.com/questions/65575093
复制相似问题