SkillsGrove
SkillsGrove/Documentos de escritório/TingdeLiu/Tyndall-Skills/pdf-compressor

pdf-compressor

Instalação

$npx skills add https://github.com/TingdeLiu/Tyndall-Skills --skill pdf-compressor
$git clone --depth 1 https://github.com/TingdeLiu/Tyndall-Skills.git /tmp/Tyndall-Skills && mkdir -p ~/.claude/skills && cp -r /tmp/Tyndall-Skills/pdf-compressor ~/.claude/skills/pdf-compressor
Por favor, instale esta Agent Skill para mim: https://github.com/TingdeLiu/Tyndall-Skills/tree/fbd42476f9a282e69c9726b613488e92a39ebe1e/pdf-compressor. Leia primeiro o SKILL.md e os scripts, e só a instale na minha pasta de skills depois de confirmar que é segura.

Resumo

Descrição original · MITAutomatically compress PDF files when they are too large for processing. Use this skill when (1) a PDF file exceeds 10MB and needs compression for efficient processing, (2) user explicitly requests PDF compression, (3) reading a PDF fails with a file size error, or (4) a PDF exceeds the 32MB API limit. Compresses using Ghostscript while maintaining acceptable quality.
O SKILL.md abaixo é reproduzido de TingdeLiu/Tyndall-Skills (commit fbd4247) sob a licença MIT. O texto não foi alterado; apenas os metadados do cabeçalho do arquivo foram omitidos, as imagens são exibidas como links e arquivos muito longos são truncados. Copyright 2026 Tingde Liu. Licença: LICENSE. Apenas o arquivo de instruções é exibido; consulte o repositório original para ver os scripts.

PDF Compressor

Automatically compress large PDF files to enable processing or reduce file size.

When This Skill Triggers

This skill automatically activates when:

  1. Large PDF detected - PDF file exceeds 10MB
  2. User requests compression - User says "compress this PDF", "this PDF is too large", etc.
  3. Read failure - Attempting to read a PDF fails with file size error
  4. API limit - PDF exceeds 32MB (Claude API hard limit)

Compression Workflow

Step 1: Check file size

import os
file_size_mb = os.path.getsize('file.pdf') / (1024 * 1024)
if file_size_mb > 10:
    # Trigger compression

Step 2: Run compression script

Use the bundled compression script:

python scripts/compress_pdf.py <input.pdf> -q ebook

Quality levels:

  • screen - 72 dpi, smallest size (use for very large files >100MB)
  • ebook - 150 dpi, balanced (default, recommended)
  • printer - 300 dpi, high quality (minimal compression)
  • prepress - 300 dpi, print-ready (minimal compression)

Options:

  • -o <output.pdf> - Save to different file (default: overwrite original)
  • --no-backup - Don't backup original file

Step 3: Verify compression

The script outputs:

  • Original file size
  • Compressed file size
  • Compression ratio (% reduction)
  • Output file path

Step 4: Proceed with compressed file

After compression, use the compressed PDF for the original task.

Usage Examples

Example 1: Automatic compression on large file

User: "Please analyze this PDF report.pdf"
[File is 25MB]

1. Check size: 25MB > 10MB threshold
2. Compress: python scripts/compress_pdf.py report.pdf -q ebook
3. Result: Compressed from 25MB to 8MB (68% reduction)
4. Proceed: Read and analyze the compressed report.pdf

Example 2: User requests compression

User: "This PDF is too big, can you compress it?"

1. Run: python scripts/compress_pdf.py document.pdf -q ebook
2. Report results to user

Example 3: API limit exceeded

User: "Extract text from this 40MB PDF"
[Exceeds 32MB API limit]

1. Compress aggressively: python scripts/compress_pdf.py file.pdf -q screen
2. If still too large, inform user and suggest manual compression
3. Otherwise proceed with compressed file

Script Reference

compress_pdf.py

Python script that uses Ghostscript for PDF compression.

Requirements:

  • Ghostscript must be installed on the system
  • Script automatically detects Ghostscript location

Installation check:

from scripts.compress_pdf import PDFCompressor
compressor = PDFCompressor()
if not compressor.is_available():
    # Ghostscript not found
    # Provide installation instructions

Programmatic usage:

from scripts.compress_pdf import PDFCompressor

compressor = PDFCompressor()
result = compressor.compress(
    input_path='large.pdf',
    output_path=None,  # None = overwrite
    quality='ebook',    # screen/ebook/printer/prepress
    backup=True         # Backup before overwrite
)

if result['success']:
    print(f"Compressed: {result['compression_ratio']}% reduction")
    print(f"New size: {result['compressed_size_mb']} MB")
else:
    print(f"Error: {result['error']}")

Compression Guidelines

When to compress

  • Always - File > 32MB (API limit)
  • Recommended - File > 10MB (performance optimization)
  • Optional - File < 10MB (only if user requests)

Quality selection

  • File > 100MB → Use screen quality (aggressive compression)
  • File 10-100MB → Use ebook quality (balanced, default)
  • File < 10MB → Use printer or prepress (minimal compression)

Compression expectations

Typical compression ratios:

  • Scanned documents - 60-80% reduction
  • Image-heavy PDFs - 50-70% reduction
  • Text-only PDFs - 30-50% reduction
  • Already compressed - 10-20% reduction (limited gains)

Handling edge cases

Ghostscript not installed:

Compression fails:

  • Try lower quality level (ebook → screen)
  • Check if PDF is corrupted
  • Suggest manual compression tools

File still too large after compression:

  • Inform user of the limitation
  • Suggest splitting PDF or extracting specific pages
  • Recommend external compression services

Implementation Notes

  • Always backup - Original file is backed up before overwriting (unless --no-backup)
  • Lossless for text - Text content remains readable at all quality levels
  • Images affected - Lower quality levels reduce image resolution
  • Speed - Compression time ~1-2 seconds per MB (varies by complexity)
  • Path handling - Script handles spaces and special characters in filenames
  • Error handling - Script validates Ghostscript availability and file existence

Troubleshooting

Script fails to find Ghostscript on Windows:

  • Check if Ghostscript is installed
  • Manually specify path if in non-standard location
  • Ensure gswin64c.exe or gswin32c.exe is in PATH

Compressed file is larger than original:

  • Original was already optimized
  • Try different quality level
  • PDF may have compression-resistant content

Compression too aggressive:

  • Use higher quality level (screen → ebook → printer)
  • Images will be sharper but file size larger
Ver o texto completo da licença (MIT)
MIT License

Copyright (c) 2026 Tingde Liu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.