Learn Claude Code Skills: PDF Processing

shareAI-lab/learn-claude-code

Use common PDF utilities and Python libraries to read, create, split and merge documents.

Contenuto aggiornato: SKILL.md
Punteggio di qualità 89/100
npx skills add shareAI-lab/learn-claude-code --skill pdf --copy
80.307Stelle12.840ForkUltimo push del repository

Informazioni sullo Skill

Use common PDF utilities and Python libraries to read, create, split and merge documents. These sample Skills accompany the Learn Claude Code repository’s agent-harness lessons. They demonstrate reusable task instructions and supporting examples; they are community teaching material rather than an official Anthropic product.

SKILL.md

Autore: shareAI-lab · shareAI-lab/learn-claude-code · MIT · SKILL.md @ 448c75b

---
name: pdf
description: Process PDF files - extract text, create PDFs, merge documents. Use when user asks to read PDF, create PDF, or work with PDF files.
---

# PDF Processing Skill

You now have expertise in PDF manipulation. Follow these workflows:

## Reading PDFs

**Option 1: Quick text extraction (preferred)**
```bash
# Using pdftotext (poppler-utils)
pdftotext input.pdf -  # Output to stdout
pdftotext input.pdf output.txt  # Output to file

# If pdftotext not available, try:
python3 -c "
import fitz  # PyMuPDF
doc = fitz.open('input.pdf')
for page in doc:
    print(page.get_text())
"
```

**Option 2: Page-by-page with metadata**
```python
import fitz  # pip install pymupdf

doc = fitz.open("input.pdf")
print(f"Pages: {len(doc)}")
print(f"Metadata: {doc.metadata}")

for i, page in enumerate(doc):
    text = page.get_text()
    print(f"--- Page {i+1} ---")
    print(text)
```

## Creating PDFs

**Option 1: From Markdown (recommended)**
```bash
# Using pandoc
pandoc input.md -o output.pdf

# With custom styling
pandoc input.md -o output.pdf --pdf-engine=xelatex -V geometry:margin=1in
```

**Option 2: Programmatically**
```python
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello, PDF!")
c.save()
```

**Option 3: From HTML**
```bash
# Using wkhtmltopdf
wkhtmltopdf input.html output.pdf

# Or with Python
python3 -c "
import pdfkit
pdfkit.from_file('input.html', 'output.pdf')
"
```

## Merging PDFs

```python
import fitz

result = fitz.open()
for pdf_path in ["file1.pdf", "file2.pdf", "file3.pdf"]:
    doc = fitz.open(pdf_path)
    result.insert_pdf(doc)
result.save("merged.pdf")
```

## Splitting PDFs

```python
import fitz

doc = fitz.open("input.pdf")
for i in range(len(doc)):
    single = fitz.open()
    single.insert_pdf(doc, from_page=i, to_page=i)
    single.save(f"page_{i+1}.pdf")
```

## Key Libraries

| Task | Library | Install |
|------|---------|---------|
| Read/Write/Merge | PyMuPDF | `pip install pymupdf` |
| Create from scratch | ReportLab | `pip install reportlab` |
| HTML to PDF | pdfkit | `pip install pdfkit` + wkhtmltopdf |
| Text extraction | pdftotext | `brew install poppler` / `apt install poppler-utils` |

## Best Practices

1. **Always check if tools are installed** before using them
2. **Handle encoding issues** - PDFs may contain various character encodings
3. **Large PDFs**: Process page by page to avoid memory issues
4. **OCR for scanned PDFs**: Use `pytesseract` if text extraction returns empty

Perché lo abbiamo scelto

Useful for learning how task instructions fit into an agent harness. The small examples make it easier to inspect the prompt, dependencies and expected output before adapting one to a real project.

A cosa serve

  • Use common PDF utilities and Python libraries to read, create, split and merge documents.

Setup and use

Run the command below, or choose the command for your agent in the installation steps.

ComandoA cosa serve
npx skills add shareAI-lab/learn-claude-code --skill pdf --copyInstall this skill from its original repository.

Upstream README and setupTask entrypoint and supporting files

Install

  1. Claude Code

    From the project directory, install this skill.

    npx skills add shareAI-lab/learn-claude-code --skill pdf -a claude-code --copy
  2. Codex

    From the project directory, install this skill.

    npx skills add shareAI-lab/learn-claude-code --skill pdf -a codex --copy
  3. Cursor

    From the project directory, install this skill.

    npx skills add shareAI-lab/learn-claude-code --skill pdf -a cursor --copy
  4. Manual copy

    Copy the complete skills/pdf folder from the original repository into the project skills directory: .claude/skills/ for Claude Code or .agents/skills/ for Codex and Cursor.

Prima di usarlo

  • Read the selected Skill and preserve its supporting resources. The course’s executable agent examples require their own Python dependencies and configured model access.

Agenti supportati

Claude Code

Fonti e riferimenti

Le fonti originali sono collegate qui sotto. Gli spunti pratici sono suggerimenti editoriali di SkillHey.