Home
Softono

RapidOCRPDF

Open source Apache-2.0 Python
188
Stars
19
Forks
1
Issues
4
Watchers
5 months
Last Commit

 About RapidOCRPDF

Based on RapidOCR, extract the PDF content

Platforms

Web Self-hosted

Languages

Python

Links

Need Help Installing RapidOCRPDF?

We provide expert installation service for this software. Our team will install, configure, and secure RapidOCRPDF on your server. plans start at just $30.

RapidOCRPDF

View on GitHub

RapidOCR 📄 PDF

PyPI SemVer2.0 GitHub

简介

本仓库依托于RapidOCR仓库,快速提取PDF中文字,包括扫描版PDF、加密版PDF、可直接复制文字版PDF。

整体流程

flowchart LR

A(PDF) --> B{是否可以直接提取内容} --是--> C(PyMuPDF)
B --否--> D(RapidOCR)

C & D --> E(结果)

安装

pip install rapidocr_pdf

使用

脚本使用

⚠️注意:在rapidocr_pdf>=0.4.0中,支持page_num_list参数为负数,假设总页数为2,范围为[-2, 1]

⚠️注意:在rapidocr_pdf>=0.3.0中,支持了page_num_list参数,默认为None,全部提取。如果指定,页码从0开始

⚠️注意:在rapidocr_pdf>=0.2.0中,已经适配rapidocr>=2.0.0版本,可以通过参数来使用不同OCR推理引擎来提速。 下面的ocr_params为示例参数,详细请参见RapidOCR官方文档:docs

from rapidocr_pdf import RapidOCRPDF

pdf_extracter = RapidOCRPDF(ocr_params={"Global.with_torch": True})

pdf_path = "tests/test_files/direct_and_image.pdf"

# page_num_list=[1]: 仅提取第2页
texts = pdf_extracter(pdf_path, force_ocr=False, page_num_list=[1])
print(texts)

命令行使用

$ rapidocr_pdf -h
usage: rapidocr_pdf [-h] [--dpi DPI] [-f] [--page_num_list [PAGE_NUM_LIST ...]] pdf_path

positional arguments:
  pdf_path

options:
  -h, --help            show this help message and exit
  --dpi DPI
  -f, --force_ocr       Whether to use ocr for all pages.
  --page_num_list [PAGE_NUM_LIST ...]
                        Which pages will be extracted. e.g. 0 1 2.

$ rapidocr_pdf tests/test_files/direct_and_image.pdf --page_num_list 0 1

输入输出说明

输入Union[str, Path, bytes]

输出List [页码, 文本内容, 置信度], 具体参见下例:

[
    [0, '人之初,性本善。性相近,习相远。', 0.8969868],
    [1, 'Men at their birth, are naturally good.', 0.8969868],
]