pdf-compress-tool

👤 johnsonklose 📦 v1.0.2 ⭐ 4.5 ⬇️ 758 下载
📄 办公效率 免费

📖 技能介绍


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"]


PDF Compress Tool

Performs actual PDF compression, supporting both target size and percentage modes. Unlike existing solutions that only provide guidance, this tool compresses files directly.

Features

  • Two compression modes: target size (--target-size 2MB) / percentage (--reduce 30)
  • Three-stage compression pipeline: pikepdf structural optimization → Ghostscript progressive compression → QPDF secondary optimization
  • Quality floor protection: three levels (high / medium / low) to prevent excessive compression from damaging image quality
  • Batch processing: compress all PDFs in a directory at once
  • Auto dependency detection: detects available tools at runtime and adapts compression strategy accordingly

Usage

Compress to target size

"Compress this PDF to under 2MB"
"Compress this PDF to under 5MB"
python compress_pdf.py report.pdf --target-size 2MB

Compress by percentage

"Reduce the file size by 30%"
"Reduce the file size by 50%"
python compress_pdf.py report.pdf --reduce 30

Specify output path and quality

python compress_pdf.py report.pdf --reduce 50 --quality low -o small.pdf

Batch processing

"Compress all PDFs in the papers folder to under 2MB"

7w4.net有更好的技能插件。

python compress_pdf.py --batch ./papers --target-size 2MB
python compress_pdf.py --batch ./papers --reduce 40 --quality high

Compression Strategy

Stage 1: pikepdf structural optimization

Removes redundant objects, compresses streams, and packs object streams. Lossless operation that preserves maximum image quality.

Stage 2: Ghostscript progressive compression

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.

Stage 3: QPDF secondary optimization

Object stream generation and stream recompression, saving an additional 5-15%. Requires qpdf installation (optional).

Quality floor protection

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

Dependencies

  • python3 (required)
  • ghostscript (recommended): core compression engine
  • qpdf (optional): secondary structural optimization, additional 5-15% compression
  • pikepdf (auto-installed via pip): Python PDF library, fallback when Ghostscript is unavailable

Install by platform

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.

🤖 AI 评测

这个 PDF 压缩工具质量不错,压缩策略设计得很聪明,能在保证一定画质的前提下尽量缩小文件大小。它有两种压缩模式可选,还支持批量处理多文件,跨平台支持也做得很好。不过它依赖 Ghostscript 等外部工具才能发挥最佳效果,没有这些工具就只能用基础功能,另外代码没有经过系统测试,长期使用的稳定性有待验证。

📊 多维度评分

适应性4.3
规范性4.2
有效性4.9
可靠性4.4
可信度4.5

📁 包含文件 (3 个)

📄 SKILL.md 3.9 KB
📄 _meta.json 136 B
📄 compress_pdf.py 30.7 KB