ocrmypdf /OCRmyPDF

OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched

★ 35,284⑂ 2,450👁 188⑃ 298● 1,388▤ 67◈ 87
PythonMPL-2.0Created 2013-12-20ocrmypdf.readthedocs.io/
35,284
stars
+11
2,450
forks
188
watchers
298
prs
1,388
issues
67
releases
87
discussions

README

[![PyPI 版本][pypi]](https://pypi.org/project/ocrmypdf/) ![Homebrew 版本][homebrew] ![ReadTheDocs][docs] ![Python 版本][pyversions]

[pypi]: https://img.shields.io/pypi/v/ocrmypdf.svg "PyPI 版本"
[homebrew]: https://img.shields.io/homebrew/v/ocrmypdf.svg "Homebrew 版本"
[docs]: https://readthedocs.org/projects/ocrmypdf/badge/?version=latest "RTD"
[pyversions]: https://img.shields.io/pypi/pyversions/ocrmypdf "支持的 Python 版本"

OCRmyPDF 会为扫描版 PDF 文件添加 OCR 文本层,使其可以搜索或复制粘贴。

bash
ocrmypdf                       它是一个可脚本化的命令行程序
   -l eng+fra                  它支持多种语言
   --rotate-pages              它可以修正旋转方向错误的页面
   --deskew                    它可以校正歪斜的 PDF!
   --title "My PDF"            它可以更改输出元数据
   --jobs 4                    它默认使用多个 CPU 核心
   --output-type pdfa          它默认生成 PDF/A
   input_scanned.pdf           接受 PDF 输入(或图像)
   output_searchable.pdf       生成经过验证的 PDF 输出


查看发布说明,了解最新变更详情。

 主要功能

- 从普通 PDF 生成可搜索的 PDF/A 文件
- 将 OCR 文本准确放置在图像下方,便于复制/粘贴
- 保持原始嵌入图像的精确分辨率
- 在可能时,以“无损”操作插入 OCR 信息,不干扰任何其他内容
- 优化 PDF 图像,通常生成比输入文件更小的文件
- 按需在执行 OCR 前校正和/或清理图像
- 验证输入和输出文件
- 在所有可用 CPU 核心间分配工作
- 使用 Tesseract OCR 引擎识别超过 100 种语言
- 保护你的私有数据。
- 可以妥善扩展,处理包含数千页的文件。
- 已在数百万份 PDF 上经过实战检验。



详情请参阅文档。

 动机

我曾在网上寻找一款免费的命令行工具来对 PDF 文件执行 OCR:我找到了很多,但没有一个真正令人满意:

- 要么生成的 PDF 文件中文本位于图像下方的错误位置(导致无法复制/粘贴)
- 要么无法处理重音字符和多语言字符
- 要么会改变嵌入图像的分辨率
- 要么生成的 PDF 文件大得离谱
- 要么在尝试 OCR 时崩溃
- 要么无法生成有效的 PDF 文件
- 除此之外,它们都不能生成 PDF/A 文件(专为长期存储设计的格式)

……所以我决定开发自己的工具。

 安装

支持 Linux、Windows、macOS 和 FreeBSD。也提供 Docker 镜像,同时支持 x64 和 ARM。

| 操作系统                      | 安装命令                       |
| ----------------------------- | ------------------------------ |
| Debian, Ubuntu                | apt install ocrmypdf       |
| Windows Subsystem for Linux   | apt install ocrmypdf       |
| Fedora                        | dnf install ocrmypdf       |
| macOS (Homebrew)              | brew install ocrmypdf      |
| macOS (MacPorts)              | port install ocrmypdf      |
| macOS (nix)                   | nix-env -i ocrmypdf        |
| LinuxBrew                     | brew install ocrmypdf      |
| FreeBSD                       | pkg install py-ocrmypdf    |
| OpenBSD                       | pkg_add ocrmypdf           |
| Ubuntu Snap                   | snap install ocrmypdf      |

其他用户请参阅我们的文档了解安装步骤。

 语言

OCRmyPDF 使用 Tesseract 执行 OCR,并依赖其语言包。对于 Linux 用户,通常可以找到提供语言包的软件包:

bash

 Debian/Ubuntu 用户
apt-cache search tesseract-ocr  显示所有 Tesseract 语言包列表
apt-get install tesseract-ocr-chi-sim   示例:安装简体中文语言包


 Arch Linux 用户
pacman -S tesseract-data-eng tesseract-data-deu  示例:安装英语和德语语言包

 OpenBSD 用户
pkg_info -aQ tesseract   显示所有 Tesseract 语言包列表
pkg_add tesseract-cym   示例:安装威尔士语语言包

 brew macOS 用户
brew install tesseract-lang

 Fedora 用户
dnf search tesseract-langpack  显示所有 Tesseract 语言包列表
dnf install tesseract-langpack-ita  示例:安装意大利语语言包




随后可以向 OCRmyPDF 传递 -l LANG 参数,提示它应搜索哪些语言。可以同时请求多种语言。

OCRmyPDF 支持 Tesseract 4.1.1+。它会自动使用 PATH 环境变量中首先找到的版本。在 Windows 上,如果 PATH 中没有 Tesseract 二进制文件,我们会根据 Windows 注册表使用已安装的最高版本号。

 文档和支持

安

Top issues

Discussions

Latest release

v17.14.0 v17.14.0 2026-11-08
New features

- New optional OCR engine, RapidOCR, which runs PaddleOCR's PP-OCR models on
  ONNX Runtime. Install it with uv tool install 'ocrmypdf[rapidocr]' (or
  uv pip install / pip install with the same extra) and select it with
  --ocr-engine rapidocr. It often reads numbers and table cells more
  accurately than Tesseract, at a higher CPU and memory cost. It supports
  --rotate-pages and --deskew without Tesseract, and the new option
  --rapidocr-max-side-len (API: rapidocr_max_side_len=) controls how far
  large pages are downscaled. See the cookbook for languages and limitations.
- W

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON