Skip to content

Add Ghostscript-based PDF compressor and update docs (fixes #129)#137

Merged
x4nth055 merged 1 commit intomasterfrom
add/pdf-compressor-ghostscript
Sep 28, 2025
Merged

Add Ghostscript-based PDF compressor and update docs (fixes #129)#137
x4nth055 merged 1 commit intomasterfrom
add/pdf-compressor-ghostscript

Conversation

@x4nth055
Copy link
Copy Markdown
Owner

This PR resolves issue #129 by adding an open-source alternative to the PDFTron/PDFNet dependency.

Problem

  • PDFTron/PDFNet now requires a license key (no longer free)
  • The PDFNetPython3 pip package is not freely available
  • Users can't run the existing pdf_compressor.py without a commercial license

Solution

  • Added pdf_compressor_ghostscript.py using Ghostscript (open-source)
  • Updated README.md to document both methods and installation instructions
  • Updated requirements.txt to note system dependencies

Features

  • Cross-platform Ghostscript executable detection (gs, gswin64c, gswin32c)
  • Quality levels 0-4 mapping to Ghostscript -dPDFSETTINGS (/screen, /ebook, /printer, /prepress, /default)
  • Same output format as original script (compression summary)
  • No Python dependencies required

Testing

Tested with bert-paper.pdf from the repo:

  • Input: 757.00KB
  • Compressed (power=1): 407.09KB
  • Compression ratio: 46.22%

Usage

# Install Ghostscript (system dependency)
# macOS: brew install ghostscript
# Ubuntu: sudo apt-get install ghostscript  
# Windows: https://ghostscript.com/releases/

# Compress PDF
python pdf_compressor_ghostscript.py bert-paper.pdf compressed.pdf 1

Fixes #129

@x4nth055 x4nth055 merged commit 2e77319 into master Sep 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF compression script example requires License Key

1 participant