Compress PDF files by downscaling embedded images.
- Rust 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
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:
- Decodes it (
DCTDecodeand raw 8-bitDeviceGray/DeviceRGBimages behindFlateDecodeare supported). - Resizes it by
--scaleusing a Catmull-Rom filter. - Re-encodes it as a JPEG at
--qualityand 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.