v17.14.22026-11-16
修复了RapidOCR在高分辨率页面上漏识细笔画字符的问题。当页面栅格化分辨率高于--rapidocr-max-side-len时(如--redo-ocr以400dpi重栅格化),RapidOCR会用插值缩小图片,采样间隙把<这类细笔画冲断,数字也容易认错。现在改由OCRmyPDF先用Lanczos滤波自行缩小,再交给RapidOCR识别。实测一份扫描的化验表,229个印刷<中文字层保留了222个,此前只有163个。
v17.14.12026-11-10
本次修复了RapidOCR引擎无法自定义模型存放位置的问题。此前模型只能保存在RapidOCR的包目录下,该目录可能是只读的,下载到容器内还会随容器退出而丢失。现在可通过新选项--rapidocrmodeldir DIR(API:rapidocrmodeldir=;环境变量:OCRMYPDFRAPIDOCRMODELDIR)指定目录,RapidOCR全部模型及页面方向模型都会保存在那里,缺失的模型会自动下载补全;也可运行python -m ocrmypdf.builtinplugins.rapidocr_ocr download --model-dir DIR提前预下载。
v17.14.02026-11-09
新增可选OCR引擎RapidOCR,在ONNX Runtime上运行PaddleOCR的PP-OCR模型,数字与表格的识别通常比Tesseract更准,代价是更高的CPU与内存开销。安装用uv tool install 'ocrmypdf[rapidocr]',启用加--ocr-engine rapidocr;新增--rapidocr-max-side-len(API:rapidocrmaxsidelen=)控制大页缩放。它无需Tesseract即可完成--rotate-pages与--deskew,页面旋转会同时参考方向模型与文本行位置,两者一致才翻页。模型可提前用python -m ocrmypdf.builtinplugins.rapidocr_ocr download下载,方便离线环境;Docker镜像默认不含该引擎,.docker/Dockerfile.rapidocr提供带RapidOCR的构建。修复方面,选择非Tesseract引擎(含--ocr-engine none)不再强制安装Tesseract;--redo-ocr与--mode strip误删混合文本中可见文字、fpdf2把上倾行文字写大并与相邻行重叠的问题也已解决。
v17.13.02026-09-29
Changes
- PDF/A made without Ghostscript ("speculative" conversion) is now validated
with pikepdf's PDF/A support (pikepdf.pdfa) instead of veraPDF, and the
final output is validated again after the metadata and optimization steps.
veraPDF is no longer used, so the Ghostscript-free path is available
whether or not veraPDF is installed, including in the Docker image. Files
the validator does not approve go to Ghostscript as before; run with -v1
to see why.
- Speculative conversion now supports PDF/A-1b, and repairs common problems
that previously always sent a file to Ghostscript: it replaces other output
intents with sRGB, removes image interpolation flags, sets the Print flag on
annotations, adds the /CIDSet PDF/A-1 requires, and removes XMP properties
and hidden annotations that PDF/A does not permit.
- New option --pdfa-backend {auto,ghostscript,internal} (API:
pdfa_backend=). auto, the default, tries OCRmyPDF's own conversion and
then Ghostscript. internal never uses Ghostscript, so JPEGs pass through
unchanged; if the result is not approved, the pdfa output types fail with
exit code 10 and --output-type auto outputs a regular PDF. ghostscript
always uses Ghostscript. Options that only Ghostscript implements
(--pdfa-image-compression, --ghostscript-jpeg-quality,
--ghostscript-jpeg-maxdpi, and --color-conversion-strategy CMYK,
Gray or UseDeviceIndependentColor) now select Ghostscript under auto
and are an error with internal.
- OCRmyPDF now requires pikepdf[pdfa] 10.15 or later. The pdfa extra
brings in jsonschema, referencing and fonttools, all packaged by
Debian and Red Hat.
- --force-ocr now keeps hyperlinks, moving link annotations onto the
rasterized page; so do --deskew and --clean-final. The new mode
--mode force-ocr-no-links keeps the old behaviour. {issue}605
- When Ghostscript substitutes fonts that are not embedded, it now always uses
its own fonts (-dNONATIVEFONTMAP), so output is the same on every
platform; on macOS, native font lookup could embed tens of megabytes of
system fonts. OCRmyPDF warns when fonts other than the standard 14 are
substituted, or when a substitute loses bold or italic styling.
{issue}1369
- A creation date without a time zone is now taken to be local time, and the
output's dates get that zone, with a warning. Set TZ to choose another
zone.
- In the default mode, a page that already has text now stops OCRmyPDF
straight after the initial scan, instead of after OCRing the pages before
it. The error names the page. {issue}613
- The check of the output file is much faster: each stream is checked in the
cheapest way for its compression instead of being fully decoded, and a
progress bar is shown. JPEG 2000 and CCITT images are now checked too, but
JPEGs that are corrupt without being truncated are no longer detected.
{issue}1570
- OCRmyPDF now ships a PyInstaller hook, so apps that use it can be bundled
without extra options. Tesseract and Ghostscript must still be installed.
{issue}1024
- New PageInfo.hasvisibletext, which excludes invisible text such as an
OCR layer. has_text is unchanged.
Fixes
- --force-ocr on a scan that already had an invisible OCR layer rasterized
it at no less than 400 dpi, as if the text were visible, which could
multiply the file size. {issue}961
- Process workers (use_threads=False on Windows and macOS) failed on every
page with 'OcrOptions' object has no attribute 'tesseract'.
{issue}1757
- ocrmypdf.ocr() rejected thresholding method names such as
tesseract_thresholding='adaptive-otsu'. {issue}1460
- --rotate-pages --tesseract-timeout 0 detected page orientation but did not
rotate the pages. The cookbook now recommends this combination for rotating
or deskewing without OCR. {issue}778
- With --output-type auto and --force-ocr, output was labelled PDF/A
without being validated or given the PDF/A declarations when veraPDF was
not installed, as in the Docker image. {issue}1751
- Ghostscript's PDF/A conversion deleted most hyperlinks (those without the
Print flag). Hidden annotations, which PDF/A does not permit, are now
removed before Ghostscript runs, with the same warning as speculative
conversion, instead of silently. {issue}605
- Text in fonts without /ToUnicode, which viewers extract through glyph
names, was garbled or lost when Ghostscript made the PDF/A. {issue}1297
- XMP metadata with no document-info equivalent, such as dc:contributor
and dc:subject, was lost when Ghostscript made the PDF/A. It is now
copied with its whole value, including every language of a multilingual
property. {issue}1220
- Images in PDFs from iText and pdftk were recompressed without their Flate
predictor, growing the output by about 30%. {issue}1620
- Copied text from vertical Japanese and other vertical or rotated OCR lines
had spurious spaces and characters out of order. {issue}1244
- Text set in the glyphless fallback font, used when no installed font
covers a script (e.g. CJK), lost characters when selected or copied in
Chrome and other pdfium-based viewers.
- A page made of full-page images at different resolutions was rasterized at
a weighted average resolution rather than the highest. {issue}948
- The document language (/Lang) was not set for Tesseract's language codes
such as deu, fra and ces. Languages without a two-letter code now get
their three-letter code. {issue}1749
- Some LaTeX PDFs with malformed numbers in a content stream, such as
0.000-50131235, stopped OCRmyPDF. It now warns and continues, as viewers
do. {issue}1054
- A /Rotate stored as a real number, or a cm operator with a non-numeric
operand, crashed the page scan.
- --force-ocr --ocr-engine none crashed on pages with no images.
- When OCRmyPDF's own PDF/A failed its final check, the Ghostscript fallback
could fail with FileExistsError; on Windows it always did.
- With the default --output-type auto, the explanation for a file that grew
now points to PDF/A conversion. {issue}1369
- Ghostscript 10.08's title 'Untitled' (with quotes) for untitled files is
removed again.
- The Docker image's web service could not find its Streamlit script. The
Docker documentation for the web service is updated. {issue}1753
- The Docker watcher no longer turns off deskew given in
OCRJSONSETTINGS when OCR_DESKEW is not set.
v17.12.12026-09-17
修复了ocrmypdf --version和--help把内容输出到标准错误的问题:此前version=$(ocrmypdf --version)取到空值,ocrmypdf --help | less也一片空白。原因是启动早期就把文件描述符1重定向到标准错误,以免插件或第三方库的杂散写入污染输出到标准管道的PDF,连带argparse的输出也被截走,现已改回真正的标准输出,报错信息仍走标准错误。该问题自v17.8.0起存在。
v17.12.02026-09-17
依赖与打包:现在要求pikepdf10.2及以上。HEIF/HEIC图片支持改为可选安装项ocrmypdf[heic],默认不再附带——原依赖的pi-heif已停更,继任者pillow-heif捆绑的libheif、libde265与x265会让整个wheel受GPLv2约束,Docker镜像与snap同样不含,需要处理HEIC的用户自行
v17.11.02026-08-29
Enhancements
- New --max-ocr-image-mpixels downsamples the image sent to OCR when a page
exceeds the given size, which bounds the largest consumer of memory. The
visible page is never downsampled, so output appearance is unaffected in every
mode; what it trades is OCR accuracy on very high resolution scans. A 34
megapixel page that peaks at 492 MB peaks at 325 MB under
--max-ocr-image-mpixels 8, and recognizes the same text. See the "Memory"
section of the performance documentation for how to size a memory limit.
- watcher.py (the watcher extra) gained a configurable output layout and
conflict policy. These are watcher-only changes; they do not affect the
ocrmypdf library API.
- New OCROUTPUTSTRUCTURE setting (--output-structure): FLAT
(default, all outputs directly in the destination directory),
YEAR_MONTH ({destination}/{year}/{month}/{filename}, same layout as
the old OCROUTPUTDIRECTORYYEARMONTH=1), or HIERARCHY, which
mirrors the input directory tree under the destination, e.g.
input/a/b/c.pdf → output/a/b/c.pdf.
- New OCRONCONFLICT setting (--on-conflict) controls what happens
when the intended destination file already exists: SUFFIX (default)
writes name (1).pdf, name (2).pdf, ... in the OS style; SKIP logs
and leaves the file unprocessed; OVERWRITE is the old behavior.
**Behavior change: the default is now SUFFIX, so existing output
files are no longer silently overwritten.**
- Both settings now apply equally to OCROUTPUTDIRECTORY and to the
archive directory used by OCRONSUCCESS_ARCHIVE; previously the
archive directory was always flat and silently overwrote on a name
collision.
- Output and archive filenames and directory components are sanitized
for filesystems more restrictive than the input side (e.g. an SMB
share): characters illegal on Windows/SMB (<>:"/\|?* and control
characters) are replaced with _, trailing dots/spaces are stripped,
and reserved DOS device names (CON, PRN, AUX, NUL, COM1-9,
LPT1-9) are prefixed with _.
- OCROUTPUTDIRECTORYYEARMONTH is now deprecated in favor of
OCROUTPUTSTRUCTURE=YEAR_MONTH. It is still honored and logs a
deprecation warning; if both are set, OCROUTPUTSTRUCTURE wins.
- See the "Watched folders with watcher.py" section of the batch
processing documentation for the full description, including a note
for SMB users about client-side directory/file-info caching delays.
Performance
- The image sent to OCR is no longer decoded and re-encoded when nothing needs
to change it. On a page with no pre-existing text to mask and no filtering
plugin -- the ordinary case for a scanned document -- the rasterized page
already is the OCR image, so it is linked rather than rewritten. Producing
it was costing 3.3 seconds and a full-size buffer on a 34 megapixel page, out
of about 15 seconds for the whole file. Building the mask is now deferred
until a text area actually needs blanking, since that step is what forced the
decode. The minimum Pillow version is raised to 12, because deciding whether
anything decoded the image reads an attribute whose shape settled in Pillow 11
(pi-heif already required Pillow 11.1, so the effective floor barely moves).
- Reduced peak memory on files with large images by about a third at default
settings. On a 34 megapixel page the process tree peaked at 752 MB and now
peaks at 492 MB. Two changes account for it: rasterizing a page no longer
allocates a third full-page buffer to correct PDFium's rounding of the
rendered size by a pixel or two, and freed heap memory is now returned to the
operating system before the OCR engine runs, instead of counting against our
resident set for as long as the engine is working. Rasterization is also
faster, since correcting the size no longer resamples the whole page.
- Several OCR jobs may now run concurrently in a single Python process. The API
previously held a lock for the whole duration of ocrmypdf.ocr(), so a second
call in another thread had to wait for the first to finish. Plugin state is
now guarded by a readers-writer lock: installing a plugin set takes it
exclusively, and a job holds it shared for its run. An in-flight job therefore
cannot have the plugin infrastructure it depends on replaced underneath it,
while jobs that are past installation proceed concurrently.
- A plugin set is now installed once per interpreter and reused, rather than
being reinstalled on every call. Previously each ocrmypdf.ocr() call
re-executed plugin modules given as file paths and rebound them in
sys.modules. Plugins must not rely on being re-executed for each job, and
must not store per-job state on the plugin manager, which concurrent jobs
requesting the same plugin set now share.
- Jobs requesting different plugin sets serialize against each other, since
installing the second set must wait for the first set's jobs to finish. Use
the same plugin set across concurrent jobs, or separate processes.
- Image optimization is substantially faster on documents with large images.
An image stored as /FlateDecode with a PNG predictor already holds exactly
what a PNG IDAT chunk holds, so it is now repackaged as a PNG directly
instead of being decoded to a bitmap and re-encoded. On a 6-page document
containing one 9000x9000 image, the optimization step went from 3.4s to 0.6s,
and to 0.04s together with the JPEG change below; total runtime went from
10.0s to 7.0s. Output is unchanged: the compressed
data is reused verbatim. Images that are not in a directly repackageable form
still take the previous path.
- During image optimization, we decoded all JPEGs, even if the code
path was an optimization setting with the decoded JPEG would be never be
re-encoded (below --optimize 2). We now decode only on code paths that
use the decoded JPEG. Output is unchanged.
- An uncompressed image (one with no /Filter) no longer produces a spurious
"could not be processed by the optimizer" warning. Such an image raised
IndexError internally, which the optimizer's best-effort handler caught and
reported as a warning; it is now recognized and skipped quietly.
- Removed an unreachable branch in the image optimizer that claimed to handle
1 bit per component images in an ICC-based colorspace. An earlier check sends
every 1 bpc image to the JBIG2 pass, which handles ICC-based images by
neutralizing the profile before extracting, so the branch could never run.
- Removed the process-wide lock that serialized worker pools across all
Executor instances. Executor.pool_lock is retained but no longer acquired,
and is deprecated; it will be removed in a future major release. The invariant
it protected - that only one progress bar renders on the shared console - is
now enforced by the progress bar, which disables itself if another bar already
owns the console.
- Note that N concurrent jobs each configured with jobs=M may now spawn up to
N*M workers, where previously they were serialized to M. Size jobs
accordingly.
- Known limitation of concurrent in-process jobs: they must use the same
maximagempixels. Pillow's decompression-bomb limit is interpreter-global
and the last job to set it wins. Use separate processes to run jobs with
differing configurations.
Fixes
- Fixed a latent use-after-free in the pypdfium2 rasterizer. to_pil() lets
Pillow alias PDFium's bitmap buffer for some formats -- grayscale renders
among them, which is every mono and grayscale page -- and the buffer was freed
immediately afterwards, leaving Pillow reading memory PDFium had released.
- Windows: OCRmyPDF no longer prints [WinError 2] The system cannot find the
file specified warnings while it searches for
v17.10.02026-08-05
这版主要围绕watcher.py监控目录助手(watcher附加组件)的安全加固。依赖从watchdog换成watchfiles,默认走操作系统原生文件通知,可用OCRUSEPOLLING=1强制轮询。启动时会做数据与代码的隔离检查:输入、输出或归档目录一旦与Python解释器路径、虚拟环境、site-packages或$PATH重叠,OCRJSONSETTINGS指向数据目录内或权限过宽的文件,或指定的插件位于数据目录中,都会拒绝运行(退出码9);输出、归档目录若落在输入目录内也一并拦下,避免OCR产出被反复处理成死循环。运行期不再跟随符号链接,也不处理fifo、设备文件等非普通文件,写入时同样拒绝覆盖非常规目标。
另外修了个烦人问题:带密码的PDF投进监控目录不会再把watcher整个带崩(#1715)——pikepdf.PasswordError并不继承自pikepdf.PdfError,漏出了等待文件写完的处理器,导致监视循环中断,后续文件全部无人处理。现在加密文件只记日志并跳过,单个文件的任何错误都不会再中止监视。
Ghostscript版本判断补上了上限,10.7.0及以上不再被误判为受JPEG直通截断bug影响(#1726);此前用户即便用的是已修复版本,仍会收到JPEG编码错误告警,并在默认--optimize 1下被悄悄有损重编码。同一套重编码规避逻辑也不再误伤Ghostscript根本没参与生成的文件,--output-type pdf和推测性PDF/A路径不再白付画质代价。数据目录与应用分开部署的环境不受影响;混放的需要调整目录结构。
v17.8.02026-07-18
OCRmyPDF本次更新主要围绕PDF/A与输出安全:--output-type auto(默认)恢复为尽量输出PDF/A——先尝试无Ghostscript的快速转换(可用时由veraPDF校验),失败再回退Ghostscript,两者都不可行才输出普通PDF(见#1561)。注意默认路径可能再次调用Ghostscript,速度更慢且会重压缩图片,赶时间可加--output-type pdf跳过转换。
同时修了几处隐患:veraPDF1.30.0及以上版本会在版本号前打印JVM警告,导致OCRmyPDF误判其不可用而跳过快速路径;含未嵌入CID(中日韩)字体的文档转PDF/A时,Ghostscript会替换并重嵌字体,把OCR文字层改坏、失去可搜索性,现在默认输出普通PDF保留文字层,显式指定--output-type pdfa则直接报错,可用--force-ocr重建。输出到标准输出(ocrmypdf input.pdf -)现在于启动早期就把文件描述符1重定向到stderr,杜绝插件或第三方库误写stdout损坏PDF,新增公共API ocrmypdf.configurestdout_protection供程序启用同样保护。另外修复了/DocumentInfo中Latin-1编码/Name键引发的未捕获UnicodeDecodeError崩溃(#1540)。
v17.7.12026-07-18
本次更新主要修复了Windows上扫描内容阶段的严重性能回退,--redo-ocr受影响最明显。此前为绕开pdfminer在缓冲区边界切分词元的bug,OCRmyPDF把读取缓冲强制设为256MiB,而Windows的CPython每次读取都会实际分配这块内存,导致上千次读取每次都要耗掉几十毫秒。上游pdfminer.six已在20250327修复该问题、20260107补上跨流切分的后续修复,因此这项兼容措施被移除,最低版本要求相应提高到20260107。
另外,OCR文本层的字体发现现在支持可变字体(如NotoSansArabic[wdth,wght].ttf,即Homebrew cask与新版Google Fonts的常见形态),此前只匹配静态的-Regular.ttf/.otf,装了正确的Noto字体仍会退回无字形字体并提示找不到字体。中日韩文字的字体匹配还做到了按语言区分,各自对应NotoSansSC、TC、HK、JP、KR,泛CJK字体仅作兜底。找不到合适字体时的警告也改写得更清楚,会说明文字虽仍可搜索复制、但在阅读器里高亮时显示为空白,并直接点名该装哪个字体族。