Skip to main content

pdfcompress-cli

PyPI version Python versions License: MIT

A multi-tier interactive and scriptable PDF compression CLI tool for Linux, macOS, and Windows.

Reduce bulky PDF documents by up to 85% with smart lossless content-stream optimization and intelligent image downsampling.


Features

  • 🚀 Interactive Wizard: Just run pdfcompress with no flags to launch a guided prompt.
  • 🎛️ Multi-Tier Compression: 3 curated compression presets from gentle lossless stream optimization to aggressive size reduction.
  • 🖼️ Image Resampling & JPEG Compression: Optimizes embedded images, normalizes color spaces, and applies Lanczos resampling.
  • ⚡ Zero External Binary Dependencies: Pure Python built on pypdf and Pillow—no ghostscript or qpdf installation needed!
  • 📦 Python Library API: Import compress_pdf directly in your Python code.
  • 📊 Real-Time Progress & Statistics: Track page processing and get exact file size savings.

Installation

Install directly via pip:

pip install pdfcompress-cli

Quick Start

1. Interactive Mode

Run the command without any arguments:

pdfcompress

The interactive wizard will prompt you for:

  1. Input PDF file path
  2. Desired compression level
  3. Output destination (with automatic default naming)

2. Command Line Usage

Compress a PDF using Medium compression (Level 2, default):

pdfcompress document.pdf
# Creates document_compressed_level2.pdf

Specify a custom compression level and output destination:

pdfcompress report.pdf -l 3 -o report_small.pdf

Force overwrite of existing output:

pdfcompress report.pdf -l 2 -o report_small.pdf -f

Compression Tiers

Tier Name Target Savings Technique Ideal For
1 Light ~10–20% Lossless stream compression; retains original images untouched Official documents, legal filings, archival
2 Medium (Default) ~40–60% Stream compression + images scaled to max 1600px @ 75% quality Email attachments, web uploads, daily sharing
3 Aggressive ~70–85% Stream compression + images scaled to max 1000px @ 40% quality Storage conservation, mobile bandwidth, quick previews

Advanced Image Fine-Tuning

You can override preset defaults with custom image quality and dimension flags:

# Custom 80% JPEG quality and max 1200px dimension
pdfcompress document.pdf -q 80 -d 1200 -o custom.pdf

CLI Options Reference

usage: pdfcompress [-h] [-l {1,2,3}] [-o OUTPUT] [-q QUALITY] [-d MAX_DIM] [-f]
                   [--keep-metadata] [-s] [-v]
                   [input]

Multi-tier PDF Compression CLI Tool

positional arguments:
  input                 Path to input PDF file

options:
  -h, --help            show this help message and exit
  -l, --level {1,2,3}   Compression tier (1=Light, 2=Medium, 3=Aggressive)
  -o, --output OUTPUT   Path for compressed output PDF
  -q, --quality QUALITY Custom JPEG quality (1-100), overrides tier default
  -d, --max-dim MAX_DIM Custom maximum image dimension in px, overrides tier default
  -f, --force           Force overwrite of output file if it exists
  --keep-metadata       Retain original document metadata (by default stripped for size)
  -s, --quiet           Quiet mode; suppress progress information
  -v, --version         show program's version number and exit

Python API Usage

You can also use pdfcompress-cli directly in your Python applications:

from pdf_compressor import compress_pdf, format_size

result = compress_pdf(
    input_path="input.pdf",
    output_path="output.pdf",
    level=2,  # 1=Light, 2=Medium, 3=Aggressive
    strip_metadata=True
)

print(f"Original size:   {format_size(result['orig_mb'])}")
print(f"Compressed size: {format_size(result['final_mb'])}")
print(f"Space saved:     {result['saved_pct']:.1f}%")

License

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

Metadata

Release files for pdfcompress-cli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdfcompress-cli 0.1.0
File Size Uploaded Provenance
pdfcompress_cli-0.1.0.tar.gz 10.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pdfcompress-cli 0.1.0
File Interpreter ABI Platform
pdfcompress_cli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / pdfcompress_cli-0.1.0.tar.gz

Download URL pdfcompress_cli-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6f86880c0690176c0f449f700606d652caa498787ce5254d204c415f40319ea8
BLAKE2b-256 checksum
How to use checksums
0b8aba5bba2292140f11a390d9add1706343939892a752cba541357052fbc4bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / pdfcompress_cli-0.1.0-py3-none-any.whl

Download URL pdfcompress_cli-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ed44e149a0fe3f6eef860d1efcf47dfbfa4f24f6833e95097efcd66d2d4437a
BLAKE2b-256 checksum
How to use checksums
a978e0dd89ac8919f9f8fa6a2cac3aa582908a2ee2788ad85fd74430df373a57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for pdfcompress-cli 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page