pdf-compress-tool — pdf-压缩-工具
v1.0.2压缩 PDF files to a tar获取 size or by percentage, using a Ghostscript + pikepdf + QPDF multi-stage 流水线.
运行时依赖
安装命令
点击复制技能文档
PDF 压缩 工具
Performs actual PDF 压缩ion, supporting 机器人h tar获取 size and percentage modes. Unlike existing solutions that only provide 图形界面dance, this 工具 压缩es files directly.
Features Two 压缩ion modes: tar获取 size (--tar获取-size 2MB) / percentage (--reduce 30) Three-stage 压缩ion 流水线: pikepdf structural optimization → Ghostscript 进度ive 压缩ion → QPDF secondary optimization 质量 floor 保护ion: three levels (high / medium / low) to 预防 excessive 压缩ion from damaging image 质量 Batch processing: 压缩 all PDFs in a directory at once Auto dependency 检测ion: 检测s avAIlable 工具s at 运行time and adapts 压缩ion strategy accordingly Usage 压缩 to tar获取 size "压缩 this PDF to under 2MB" "压缩 this PDF to under 5MB"
python 压缩_pdf.py 报告.pdf --tar获取-size 2MB
压缩 by percentage "Reduce the file size by 30%" "Reduce the file size by 50%"
python 压缩_pdf.py 报告.pdf --reduce 30
Specify 输出 path and 质量 python 压缩_pdf.py 报告.pdf --reduce 50 --质量 low -o small.pdf
Batch processing "压缩 all PDFs in the papers folder to under 2MB"
python 压缩_pdf.py --batch ./papers --tar获取-size 2MB python 压缩_pdf.py --batch ./papers --reduce 40 --质量 high
压缩ion Strategy Stage 1: pikepdf structural optimization
移除s redundant objects, 压缩es 流s, and packs object 流s. Lossless operation that preserves maximum image 质量.
Stage 2: Ghostscript 进度ive 压缩ion
Tries prepress → printer → ebook → screen 进度ively, 检查ing at each level and 停止ping as soon as the tar获取 is met. Also supports custom DPI downsampling (100 → 72 → 50 → 36 dpi), subject to 质量 floor 保护ion.
Stage 3: QPDF secondary optimization
Object 流 generation and 流 re压缩ion, saving an 添加itional 5-15%. Requires qpdf 安装ation (optional).
质量 floor 保护ion Level Meaning Minimum 压缩ion level Use case high 质量 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 压缩ion engine qpdf (optional): secondary structural optimization, 添加itional 5-15% 压缩ion pikepdf (auto-安装ed via pip): Python PDF 库, fallback when Ghostscript is unavAIlable 安装 by 平台 Dependency macOS Linux (Debian/Ubuntu) Linux (RHEL/Fedora) Windows ghostscript brew 安装 ghostscript sudo apt-获取 安装 ghostscript sudo dnf 安装 ghostscript choco 安装 ghostscript or 下载 qpdf brew 安装 qpdf sudo apt-获取 安装 qpdf sudo dnf 安装 qpdf choco 安装 qpdf or 下载 pikepdf pip 安装 pikepdf (auto) pip 安装 pikepdf (auto) pip 安装 pikepdf (auto) pip 安装 pikepdf (auto)
The script auto-检测s your 平台 and shows the correct 安装 command when a dependency is missing.