agentleFS
TingdeLiuTingdeLiu/Tyndall-Skills/pdf-compressor/SKILL.md

pdf-compressor

Skill8 starsChanged 44 days agoMITView on GitHub

Automatically 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.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the bundled compression script:

    line 32
  2. Distinctive:

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

    line 58
  3. Distinctive:

    Check if PDF is corrupted

    line 166
  4. Distinctive:

    Check if Ghostscript is installed

    line 186
  5. Very specific:

    Ensure gswin64c.exe or gswin32c.exe is in PATH

    line 188
  6. Distinctive:

    Use higher quality level (screen → ebook → printer)

    line 196

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.