Compress PDF files by downscaling embedded images.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-10 23:36:10 +02:00
src Fixed a typo. 2026-07-10 23:36:10 +02:00
.gitignore Initial commit. 2026-07-08 21:25:26 +02:00
Cargo.lock Fixed a typo. 2026-07-10 23:36:10 +02:00
Cargo.toml Fixed a typo. 2026-07-10 23:36:10 +02:00
LICENSE Initial commit. 2026-07-08 21:25:26 +02:00
README.md Initial commit. 2026-07-08 21:25:26 +02:00

pdf-compress

A small command-line tool that compresses PDF files by downscaling the images embedded in them and re-encoding them as JPEG.

Usage

Usage: pdf-compress [OPTIONS] <FILE>...

Arguments:
  <FILE>...  PDF files to compress

Options:
  -s, --scale <SCALE>      Scale factor for image dimensions (0-1) [default: 0.5]
  -q, --quality <QUALITY>  JPEG encoding quality (1-100) [default: 60]
  -h, --help               Print help
  -V, --version            Print version

Each input <FILE> is written back next to it as <FILE>-compressed.pdf, the original is never modified.

Example:

pdf-compress --scale 0.7 --quality 80 scan.pdf

How it works

For every image XObject in the document, the tool:

  1. Decodes it (DCTDecode and raw 8-bit DeviceGray / DeviceRGB images behind FlateDecode are supported).
  2. Resizes it by --scale using a Catmull-Rom filter.
  3. Re-encodes it as a JPEG at --quality and swaps it with the original.

Anything the tool can't decode is left untouched.

License

This project is licensed under the MIT License - see the LICENSE file for details.