213.1. ocrmypdf-17.12.1
Adds an invisible OCR text layer to a scanned PDF, in place
The build-state snapshot was taken from 17.12.1-1; this recipe is 17.12.1-2, so the size, time and contents below describe the earlier build.
| Version | 17.12.1, release 2 |
| Shelf | printing — Printing, printer drivers, labels, scanning and OCR |
| Phase | 42_graphics (Graphics Stack), 152 of 189 in build order |
| Licence | MPL-2.0 AND MIT AND LGPL-3.0-only AND LGPL-3.0-or-later |
| Homepage | https://github.com/ocrmypdf/OCRmyPDF |
| Build time | 1.5 SBU |
| Installed size | 19.1 MiB in 746 files |
| Recipe | ports/core/printing/ocrmypdf/kpkgbuild |
About
OCRmyPDF adds an invisible, searchable text layer to a scanned PDF and leaves the scanned images as they are. It is a Python program that drives other tools: tesseract reads the page, pypdfium2 rasterises it by default, fpdf2 writes the text layer, and ghostscript produces PDF/A output.
Why it is in KDOS
The comment above it in script/phases/42_graphics/packages.d/printing.txt:
A scanned page is an image until something puts text behind it. tesseract reads it, pdfium rasterises it and fpdf2 writes the text layer; ghostscript makes the PDF/A. ocrmypdf is the one command that adds an invisible text layer and leaves the scan itself alone.
Sources
ocrmypdf-17.12.1.tar.gz(7.3 MiB)
sha256aca73a23a80cf2f46a4c15040b0035203dbf74054b7a0c3a7ee93b05abc555a6
upstream: https://files.pythonhosted.org/packages/source/o/ocrmypdf/ocrmypdf-17.12.1.tar.gz
archive copy: sources-3/printing--ocrmypdf-17.12.1.tar.gzocrmypdf-vendor-17.12.1.tar.xz(15.0 MiB)
sha256ae49147cb5d37898dcfd6436e475bf3c0e9e33e79fbf7bd2d16d1b3008288099
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-3/printing--ocrmypdf-vendor-17.12.1.tar.xz
Dependencies
Depends on: python3, python3-pip, python3-rich, python3-typing-extensions, python3-charset-normalizer, python3-pillow, python3-pikepdf, python3-pluggy, python3-lxml, python3-cryptography, python3-packaging, python3-pygments, python3-pypdfium2, python3-pydantic-core, python3-uharfbuzz, python3-pillow-heif, python3-defusedxml, fonttools, tesseract, ghostscript, qpdf.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/42_graphics/phase.env && kpkg install ocrmypdf'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/printing/ocrmypdf.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/printing/ocrmypdf
echo 'aca73a23a80cf2f46a4c15040b0035203dbf74054b7a0c3a7ee93b05abc555a6 ocrmypdf-17.12.1.tar.gz' | sha256sum -c -
echo 'ae49147cb5d37898dcfd6436e475bf3c0e9e33e79fbf7bd2d16d1b3008288099 ocrmypdf-vendor-17.12.1.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/ocrmypdf
SRC=$SRC_ROOT/ocrmypdf-17.12.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ocrmypdf-17.12.1.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers pyrequirements, pyruntime and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
mkdir -p vendor
tar -xf $PORT_SRC/$name-vendor-$version.tar.xz --strip-components=1 -C vendor
rm -f src/ocrmypdf/data/Occulta.ttf
python3 - <<'PY'
import os, sys, time
epoch = float(os.environ["SOURCE_DATE_EPOCH"])
time.time = lambda: epoch
sys.path.insert(0, "scripts")
import generate_glyphless_font
generate_glyphless_font.main()
PY
test -s src/ocrmypdf/data/Occulta.ttf
pip3 install --ignore-installed --no-deps --no-index --find-links=vendor --root=$PKG --prefix=/usr \
annotated-types fpdf2 img2pdf pdfminer.six pydantic typing-inspection .
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/ocrmypdf, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf ocrmypdf-17.12.1-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/ocrmypdf, and runs the triggers its paths call for.
Contents
Installed programs: dumppdf.py, img2pdf, img2pdf-gui, ocrmypdf, pdf2txt.py.
Installed directories: /usr/lib/python3.14/site-packages/annotated_types, /usr/lib/python3.14/site-packages/annotated_types-0.8.0.dist-info, /usr/lib/python3.14/site-packages/fpdf, /usr/lib/python3.14/site-packages/fpdf2-2.8.8.dist-info, /usr/lib/python3.14/site-packages/img2pdf-0.6.3.dist-info, /usr/lib/python3.14/site-packages/ocrmypdf, /usr/lib/python3.14/site-packages/ocrmypdf-17.12.1.dist-info, /usr/lib/python3.14/site-packages/pdfminer, /usr/lib/python3.14/site-packages/pdfminer_six-20260107.dist-info, /usr/lib/python3.14/site-packages/pydantic, /usr/lib/python3.14/site-packages/pydantic-2.13.5.dist-info, /usr/lib/python3.14/site-packages/typing_inspection, /usr/lib/python3.14/site-packages/typing_inspection-0.4.4.dist-info, /usr/share/licenses/ocrmypdf.
Notes
The text layer is set in Occulta, a glyphless font upstream ships prebuilt as src/ocrmypdf/data/Occulta.ttf. build.sh deletes that file and regenerates it from upstream’s own scripts/generate_glyphless_font.py with fonttools, so the installed font is built from source like every other payload (What is built from source). The script stamps the font’s creation and modification dates with time.time(); the inline Python replaces time.time with SOURCE_DATE_EPOCH before calling it, so two builds write the same bytes (Reproducible packages). test -s stops the build if the script wrote nothing.
The Python modules that only OCRmyPDF uses come from the vendor bundle, ocrmypdf-vendor-<version>.tar.xz, which ports/fetch fills with the source distributions of the recipe’s pypackages list (pydantic, annotated-types, typing-inspection, fpdf2, img2pdf and pdfminer.six) and the build backends pip needs to build them. Everything else it imports is a port in depends, and pip3 install --no-deps --no-index installs exactly the six named distributions and OCRmyPDF itself, resolving nothing: a distribution missing from the bundle fails the build, and a dependency missing from depends is not noticed until the program imports it. See The three Python keys.
pydantic is pinned in pypackages because its compiled half is the separate python3-pydantic-core port, held with series at the one version that pydantic release requires. A bump of the pin here must move that port with it.
runtime = fonttools: the default renderer, fpdf2, builds the text layer with the fpdf module this package carries, which imports fontTools on its first import. The import is in a submodule the run-time needs record does not read, and fonttools is a build-only port, so without the word a prebuilt install would leave it out and every OCR run would stop with No module named 'fontTools'.