New
Apps 6,235Makers 6,214This week 13
Promote your app−30%
PDF Tooling screenshot 1
5views in
the last 30 days

PDF Tooling

PDF toolkit CLI in Python: merge, split, extract, rotate and convert to images

Built with Claude Code

by armandoherra · Unclaimed · from MXMexico · added Oct 29, 2026
no ratings0 comments

An Apache-2.0 PDF toolkit CLI in Python. One safe command-line tool (pdftooling) for the common PDF chores — merge, split, extract, delete, rotate, reorder, rasterize, compose, create, text, tables, compress, repair, linearize, encrypt, decrypt, permissions, meta, watermark, stamp, ocr and convert, plus doctor, info and version — built on a permissively licensed engine stack (pypdf, pypdfium2, reportlab, pikepdf, pdfplumber, Tesseract, LibreOffice) with nothing AGPL or GPL on the call graph.

Safety is first-class: a global --dry-run, no-clobber by default, atomic write-to-temp-then-rename, and inputs that are never mutated unless you ask for --in-place.

Getting Started

To try it without installing anything permanently, run it through uv:

uvx pdf-tooling --help

pdf-tooling merging, compressing and previewing a batch

To keep it:

uv tool install pdf-tooling
# or: pip install pdf-tooling
pdftooling --help

From source

# Prerequisites: Python >= 3.11 and uv (https://docs.astral.sh/uv/)
git clone https://github.com/ArmandoHerra/pdf-tooling.git
cd pdf-tooling
uv sync
uv run pdftooling --help

Platforms. Linux and macOS. macOS 15 or later on Apple silicon; Intel Macs are not supported. The reason is pikepdf, a runtime engine, which publishes its macOS wheels only as macosx_15_0_arm64.

uv sync installs the runtime stack and the development tooling, so there is no separate bootstrap step.

Recipes

Each recipe runs as written once its input files exist. Under uvx, write uvx pdf-tooling where a recipe says pdftooling.

Merge

pdftooling merge chapter1.pdf chapter2.pdf -O book.pdf

The output is a new file: an existing book.pdf is never overwritten unless you pass -f.

Compress

pdftooling compress book.pdf -O book-small.pdf

The default pass is structural. --images downsample adds an opt-in, lossy image pass; see Compression ceiling below for what to expect.

OCR

pdftooling ocr scan.pdf -O scan-searchable.pdf

ocr needs the tesseract binary, and pdftooling doctor says whether it resolved. No accuracy is claimed for the result.

Encrypt, and open it again, with password files

chmod 600 owner.txt user.txt
pdftooling encrypt book.pdf --owner-password-file owner.txt --user-password-file user.txt -O book-locked.pdf
pdftooling decrypt book-locked.pdf --password-file user.txt -O book-open.pdf

Put each password on a line of its own file with an editor or a secrets manager, or pass - to read it from standard input. Never echo or printf a password into a file: that puts it in your shell history. Passwords are never accepted as flag values. encrypt takes the --owner-password-file and --user-password-file pair; decrypt takes --password-file.

Preview, then script against it

pdftooling --dry-run compress chapter1.pdf chapter2.pdf --out-dir small -o json | jq -r '.items[] | "\(.input) -> \(.output) ok=\(.ok)"'

A dry run writes nothing and reports the exit code the real run would return.

What exists today

The CLI spine, the output contract and the exit-code contract are in place end-to-end, and every verb named at the top of this file — structure, raster, compose, text, optimize, crypto and overlay operations alike — is shipped behind them, not merely specified.

The complete top-level roster, by family:

Family Commands
Structure merge, split, extract, delete, rotate, reorder
Raster & compose rasterize, compose, create
Text text, tables
Optimize compress, repair, linearize
Crypto encrypt, decrypt, permissions
Metadata & overlay meta (get / set), watermark, stamp
Engine-backed ocr, convert
Diagnostics doctor, info, version

That table is asserted against the live command tree by set-inclusion, so a verb shipped tomorrow turns the check red with no author action — but uv run pdftooling --help remains the authoritative list.

uv run pdftooling --help               # the full verb tree; always the authoritative list
uv run pdftooling doctor               # which engines resolved, and how
uv run pdftooling merge a.pdf b.pdf -O merged.pdf
uv run pdftooling rotate report.pdf --pages 2-4 --angle 90 -O rotated.pdf
uv run pdftooling compress report.pdf -O small.pdf
uv run pdftooling --version            # tool, Python and engine versions on one line

uv run pdftooling --help is the authoritative list of what is actually available at any moment — if a verb is not printed there, it does not exist yet.

Page selection across verbs. split always operates on the whole document and takes no --pages; to act on a subset of pages, use extract (keep a subset), delete (remove pages) or reorder (permute), each of which accepts --pages.

When to use something else

Cells are read from each project's own README or documentation. "Not listed" means the feature does not appear in that source, not that it cannot be done.

Tool License Built in OCR Office → PDF Encryption Windows Pick it when
pdf-tooling Apache-2.0 Python yes (tesseract) yes (LibreOffice) yes no; Linux and macOS on Apple silicon you want the common chores behind a single CLI with a public JSON and exit-code contract, a global --dry-run, and nothing AGPL, GPL or LGPL on the call graph
qpdf Apache-2.0 C++ no; it does not render PDFs or extract text not listed yes yes (release assets) you need linearization, encryption, splitting, merging or inspection from a native binary or a C++ library. pdf-tooling reaches the qpdf library through pikepdf
pdfcpu Apache-2.0 Go not listed not listed yes yes (release assets) you need Windows binaries, a Go library, or commands pdf-tooling does not have: bookmarks, attachments, portfolio, form, signatures, nup and booklet
pdfly BSD-3-Clause Python, on pypdf not listed not listed not listed not stated; pure Python you want a small pure-Python CLI that can sign a PDF and verify it with check-sign, or lay pages out with booklet
OCRmyPDF MPL-2.0 Python yes; adding a text layer is its purpose not listed not listed yes (native Windows install documented) OCR is the whole job and you need --deskew, --rotate-pages, PDF/A output via --output-type pdfa or --jobs for multi-core runs; pdf-tooling's ocr offers --lang, --dpi, --psm, --pages and --skip-text-pages

Sources:

Checked on 2026-10-08.

Output contract

Rendered payloads go to stdout; diagnostics, warnings and progress go to stderr. -o selects the shape and defaults to table when stdout is a terminal and json when it is not, so piping into jq needs no flag.

Shape Behaviour
-o table An aligned, plain-text table.
-o json One object, carrying schema_version.
-o ndjson One object per item, one per line, each line carrying its own schema_version so a single streamed line is self-describing.

-o table is the shape meant for a person reading a terminal. Its columns, their names, their order and the whole layout may change in any release, without a major version bump, so anything that parses output should ask for -o json or -o ndjson instead — the structured shapes this section freezes.

Errors are the one deliberate asymmetry: with -o table an error is a one-line error: … on stderr, but with -o json/-o ndjson it is an object on stdout, so a machine consumer reading stdout never has to also read stderr to learn that the run failed. That holds for every failure you can reach, an unknown flag and a missing argument included: those are usage errors (exit 2) carrying the same envelope, not a human Usage: block.

A command group does not take the global block. meta groups meta get and meta set, and the global flags are declared at the root and on every verb, never on a group — so pdftooling meta -o json is a usage error (exit 2) rather than a run. It names the two positions that do work: pdftooling -o json meta get FILE (before the group) and pdftooling meta get FILE -o json (after the subcommand).

Global flags with no command at all — pdftooling -o json — are an incomplete invocation and exit 2 as well, pointing at --help. pdftooling on its own, with no arguments, still prints help and exits 0.

The collection key

Every -o json envelope that carries a collection of rows carries them under items. doctor and info additionally publish that same list under a name of their own, and both names are frozen: doctor's ports is pinned by the plan's own pdftooling doctor -o json | jq '.ports[] | select(.available == false)' example, and info's documents is its shipped shape. Neither is being renamed. The alias was added beside them so that a single jq expression works against every verb.

Verb Primary key Universal alias Relationship
every verb that returns an operation result items items the same list
info documents items the same list
doctor ports items the same list

meta get publishes a single document's report rather than a collection, so it has no row collection and names none.

Every -o json envelope also carries exit_code, warnings and duration_ms, on every verb. warnings is a list and is [] when empty — never null, never absent. exit_code is the code the process exits with for the run the envelope describes, and duration_ms is 0 on the verbs whose output must be reproducible byte-for-byte.

A batch reports every input, and never denies a file it wrote

A multi-input run writing into --out-dir records every input by name, in command-line order, in the payload's collection — the inputs that succeeded and the input that failed alike. A failing input is recorded, the run continues, and the run exits 1 at the end; each row carries its own ok, exit_code and message. A row that succeeded names its artifact in output, and that path is on disk.

That includes an input that failed because of its password: its row carries exit_code 6, and the run still exits 1. A --dry-run that does not test a supplied password (see Exit codes) predicts such a row as planned.

This is a behaviour change on a failure path, inside the pre-1.0.0 window. A multi-input --out-dir failure used to emit the error envelope — {"schema_version": 1, "error": {…, "path": null}}, with no collection at all — in place of the operation envelope, so the input that succeeded went unreported and the input that failed went unnamed even while its sibling's artifact sat on disk. A script that parsed such a failure by reading payload["error"] now finds payload["items"] instead. schema_version stays 1: no key is renamed, removed, retyped or repurposed, and the error envelope itself is unchanged.

Failures that are properties of the invocation rather than of an input stay run-scoped and keep the error envelope: a usage error, a directory where a file was expected, a nonexistent input, a missing engine, and the refusals the safety gate raises. A missing engine fails identically for every input, so it stays a single accurate diagnosis carrying its own exit code rather than becoming a row per input that also changes what the process exits with. A single-input run likewise reports that item's own code, which is what keeps the per-input codes distinguishable at all.

schema_version is 1, and this is what would move it

schema_version is 1 and stays 1 for as long as the envelope changes only by addition. Adding a key never moves it; nor does adding a verb, an item field, or an output format. It increments on the first change a consumer that reads keys by name cannot survive, which is exactly this list:

  • a published key is renamed;
  • a published key is removed;
  • a published key's type changes — including [] becoming null, or a scalar becoming an object;
  • a published key's meaning changes while its name and type stay the same.

An increment requires a major version bump; a major version bump does not require an increment.

The structured shapes and the exit-code table below are public API from v1.0.0. Breaking either requires a major version bump and a schema_version increment. Pre-1.0 releases are explicitly still moving.

Exit codes

Uniform across every verb.

Code Name Meaning
0 OK Success — including an empty-but-valid report. A --dry-run mirrors the code the real run would return, so it is not always 0 — except where an out-of-process engine decides the operand at load time, which a preview may not start, and except where a supplied password's correctness would decide it, which a preview declines to test; see the notes below this table.
1 FAILURE The operation ran and failed — corrupt input, engine error, unwritable destination.
2 USAGE Bad invocation — unknown flag, mutually exclusive flags, malformed page range, unknown subcommand, a global flag at a command group, or global flags with no command.
3 ENGINE_MISSING A required engine or binary is unavailable. The message always carries an install hint.
4 NO_INPUT Valid invocation, nothing to act on.
5 REFUSED A safety gate declined.
6 AUTH Password required, incorrect, or of the wrong kind.

The carve-out on code 0, and its limit. convert and ocr hand the operand to a system binary — soffice and tesseract — and a --dry-run may not start either: a preview writes nothing, anywhere, and starting an engine to look would break that. The spawn-free triage a preview does run decides the container, not the engine's verdict on the package inside it, so a readable, marker-bearing office document that soffice then refuses at load time predicts 0 and really exits 1. Every dry item of those verbs therefore carries engine_verified set to false in its detail, so the preview never reads as an unqualified success. The limit is exact: the carve-out covers an out-of-process engine's decision about an operand, and nothing else.

The carve-out on code 0 for a supplied password, and its limit. Whether a password can be resolved — a flag, an environment variable, a terminal to prompt at — is decidable from existence alone, so a preview predicts it: an encrypted operand with no password to resolve predicts 6 and exits 6. Whether a resolved password is correct is decidable only by trying it, and a preview that tried it would have read the secret inside the planning path and published a right-or-wrong verdict into plans that land in CI artifacts — a preview must not become an oracle. So an encrypted document reached with a resolvable but wrong password predicts 0 and really exits 6, wherever the preview plans without opening it. Every dry item that names a password source therefore also carries password_verified set to false in its detail, so the preview never reads as a verified success. The limit is exact: the carve-out covers a supplied password's correctness, and nothing else.

Safety contract

  • --dry-run plans and reports; it writes nothing, anywhere.
  • Outputs never clobber. An existing target needs -f/--force. On a non-interactive run, overwriting in a multi-input invocation (merge, delete, convert, etc.) additionally requires -y: bulk (more than a single input) plus destructive (in-place or clobbering) on a non-terminal stdin is refused with exit 5 rather than prompted.
  • Every write is write-to-temp-on-the-target-filesystem, fsync, then an atomic rename.
  • A hard kill — SIGKILL, the kernel's OOM killer, or a CI timeout that escalates to SIGKILL — cannot be handled by any process, so it can leave hidden temp files named .pdftoolkit- followed by a short random suffix, mode 0600, beside the destination. Your file is untouched: a temp is only ever renamed over it once complete. pdftooling never deletes these files, including on a later run into the same directory, because a leftover is the only evidence that a run was killed. pdftooling doctor --strict, run from a directory that contains the destination, lists them; delete them once no pdftooling run is writing to that directory.
  • An output keeps the permission bits of the file it replaces, and a destination that did not exist is created at 0666 & ~umask — what a shell redirect would have produced. The .bak sidecar keeps the original's bits too, so a backup is never more permissive than the file it backs up.
  • Inputs are never mutated unless you pass --in-place, which writes a .bak sidecar first. --no-backup suppresses the sidecar and requires --in-place — on its own it is a usage error.
  • An encrypted input is never written out unencrypted by default: the verbs that write a PDF from it — rotate, extract, delete, reorder, merge, split, watermark, stamp, ocr, compress, repair, linearize, meta set — refuse it unless --allow-decrypted-output is given (see What a write does not carry). A verb that writes no PDF (an extraction or report verb) is not gated, and encrypt and decrypt change encryption by design.
  • A password is never accepted as a command-line value. --password-file takes a path or -, because argv is world-readable in /proc and lands in shell history.

Compression ceiling

Structure-level compression plus optional image downsampling is the ceiling of a permissive stack: Ghostscript is AGPL-3.0+ and deliberately excluded, so compress builds on pikepdf/libqpdf object streams and an opt-in Pillow image pass instead. --images downsample's resample threshold is computed against the page's own width in inches (the page box), never an image's placement rectangle, which under-downsamples a small image on a large page — a stated, conservative limitation.

Render budget

No page of any PDF may make rasterize or ocr allocate a bitmap above 178,956,970 pixels (width times height). The budget is per page and is compared on the bitmap the renderer allocates, after the page's own crop box and /Rotate are applied; the renderer does not apply /UserUnit, so neither does the budget. A page over the budget refuses the whole run at exit 5 before anything is written, and --dry-run predicts the same refusal. The message names the page, its pixel size, the budget and the largest whole --dpi that fits (and the largest --width, under --width).

rasterize --dpi above 2400 (or not finite) and --width above 32768 exit 2. ocr inherits the area budget and keeps its own --dpi range. Under ocr --skip-text-pages, a page that is not rendered is not mea

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#pdf · #cli · #python