name: pdf-compress-tool description: "Compress PDF files to a target size or by percentage, using a Ghostscript + pikepdf + QPDF multi-stage pipeline." version: "1.0.0" metadata: openclaw: requires: bins: - python3 optional: - kind: brew formula: ghostscript bins: [gs] - kind: brew formula: qpdf bins: [qpdf] emoji: "📄" os: ["macos", "linux", "windows"]
Performs actual PDF compression, supporting both target size and percentage modes. Unlike existing solutions that only provide guidance, this tool compresses files directly.
--target-size 2MB) / percentage (--reduce 30)"Compress this PDF to under 2MB"
"Compress this PDF to under 5MB"
python compress_pdf.py report.pdf --target-size 2MB
"Reduce the file size by 30%"
"Reduce the file size by 50%"
python compress_pdf.py report.pdf --reduce 30
python compress_pdf.py report.pdf --reduce 50 --quality low -o small.pdf
"Compress all PDFs in the papers folder to under 2MB"小蔥技能有更好的技能skills外掛。
python compress_pdf.py --batch ./papers --target-size 2MB
python compress_pdf.py --batch ./papers --reduce 40 --quality high
Removes redundant objects, compresses streams, and packs object streams. Lossless operation that preserves maximum image quality.
Tries prepress → printer → ebook → screen progressively, checking at each level and stopping as soon as the target is met. Also supports custom DPI downsampling (100 → 72 → 50 → 36 dpi), subject to quality floor protection.
Object stream generation and stream recompression, saving an additional 5-15%. Requires qpdf installation (optional).
| Level | Meaning | Minimum compression level | Use case |
|---|---|---|---|
high |
Quality priority | printer (300dpi) | Documents intended for printing |
medium |
Balanced (default) | ebook (150dpi) | Everyday use |
low |
Size priority | screen (72dpi) and below | Screen viewing only |
| Dependency | macOS | Linux (Debian/Ubuntu) | Linux (RHEL/Fedora) | Windows |
|---|---|---|---|---|
| ghostscript | brew install ghostscript |
sudo apt-get install ghostscript |
sudo dnf install ghostscript |
choco install ghostscript or download |
| qpdf | brew install qpdf |
sudo apt-get install qpdf |
sudo dnf install qpdf |
choco install qpdf or download |
| pikepdf | pip install pikepdf (auto) |
pip install pikepdf (auto) |
pip install pikepdf (auto) |
pip install pikepdf (auto) |
The script auto-detects your platform and shows the correct install command when a dependency is missing.
這個 PDF 壓縮工具質量不錯,壓縮策略設計得很聰明,能在保證一定畫質的前提下儘量縮小檔案大小。它有兩種壓縮模式可選,還支援批次處理多檔案,跨平臺支援也做得很好。不過它依賴 Ghostscript 等外部工具才能發揮最佳效果,沒有這些工具就只能用基礎功能,另外程式碼沒有經過系統測試,長期使用的穩定性有待驗證。