Skip to main content
ClaudeWave
Skill2.5k repo starsupdated today

pdf

The PDF skill handles comprehensive PDF operations including text and table extraction, merging and splitting documents, rotating pages, adding watermarks, creating new PDFs, filling forms, encrypting or decrypting files, extracting images, and performing OCR on scanned documents. Use this skill whenever a user mentions PDF files or requests PDF generation or manipulation.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/UnicomAI/wanwu /tmp/pdf && cp -r /tmp/pdf/configs/microservice/bff-service/configs/agent-skills/wanwu/pdf ~/.claude/skills/pdf
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# PDF Processing Guide

## Overview

This guide covers essential PDF processing operations using Python libraries and command-line tools. For advanced features, JavaScript libraries, and detailed examples, see REFERENCE.md. If you need to fill out a PDF form, read FORMS.md and follow its instructions.

## ⚠️ Important: Avoid Common Mistakes

**Problem**: PDF content overflow, missing text, no line wrapping

**Root Cause**: Using `drawString()` instead of `Paragraph()`

**❌ Wrong**:
```python
c = canvas.Canvas("output.pdf")
c.drawString(100, 750, "Long text will overflow and be lost...")
```

**✅ Correct**:
```python
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import ParagraphStyle

doc = SimpleDocTemplate("output.pdf")
style = ParagraphStyle('Custom', fontName='STSong-Light', fontSize=11)
story = [Paragraph("Long text will wrap automatically", style)]
doc.build(story)
```

**📖 See**: [BEST_PRACTICES.md](BEST_PRACTICES.md) for detailed solutions

## Quick Start

### Creating PDFs (Recommended Approach)

```python
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.cidfonts import UnicodeCIDFont

# Register Chinese font
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))

# Create document
doc = SimpleDocTemplate("output.pdf", pagesize=A4,
                       rightMargin=2*cm, leftMargin=2*cm,
                       topMargin=2*cm, bottomMargin=2*cm)

# Create style
style = ParagraphStyle(
    'CustomBody',
    fontName='STSong-Light',
    fontSize=11,
    leading=16,
    firstLineIndent=22
)

# Build content
story = []
story.append(Paragraph("标题文本", ParagraphStyle('Title', fontName='STSong-Light', fontSize=18)))
story.append(Paragraph("正文内容会自动换行,不会超出页面边界。", style))

# Generate PDF
doc.build(story)
```

**Key Points**:
- ✅ Use `Paragraph` for automatic line wrapping
- ✅ Use `SimpleDocTemplate` for proper margins
- ✅ Register `STSong-Light` for Chinese text
- ✅ Use `Times-Roman` for English text (PDF built-in, no registration needed)

### Reading PDFs

```python
from pypdf import PdfReader

# Read a PDF
reader = PdfReader("document.pdf")
print(f"Pages: {len(reader.pages)}")

# Extract text
text = ""
for page in reader.pages:
    text += page.extract_text()
```

## Chinese Font Support

This skill includes intelligent font support with automatic font selection for Chinese and English text.

### Available Fonts

**Primary Fonts (Recommended)**:
- **STSong-Light (宋体)** - CIDFont, built-in to PDF readers, no file needed
- **Times-Roman (新罗马)** - PDF built-in font, similar to Times New Roman, no file needed

**Fallback Fonts (TTF/OTF)**:
- **Noto Serif CJK SC (宋体)** - OTF version, requires font file
- **Noto Sans CJK (黑体)** - Alternative Chinese font
- **WenQuanYi Zen Hei (文泉驿正黑)** - Alternative Chinese font
- **WenQuanYi Micro Hei (文泉驿微米黑)** - Lightweight Chinese font
- **Liberation Serif** - TTF version of Times New Roman

### Why CIDFont is Better

**STSong-Light (CIDFont)** advantages:
- ✅ **No font files needed** - Built into PDF readers
- ✅ **Smaller PDF files** - No font embedding required
- ✅ **Perfect compatibility** - Standard Adobe CID font
- ✅ **Full Unicode support** - Complete Chinese character set
- ✅ **Faster processing** - No font file loading
- ✅ **Avoids TTC errors** - No TTC format compatibility issues

### ⚠️ Important: TTC File Format Issue

**Problem**: ReportLab does not support TTC (TrueType Collection) font files.
- Error: `TTFError: TTC file "xxx.ttc": postscript outlines are not supported`
- TTC files like `NotoSerifCJK-Regular.ttc` cannot be used directly

**Solution**:
1. **Use CIDFont (STSong-Light)** - Recommended, no file needed
2. **Use OTF or TTF format** - Supported by ReportLab
3. **This skill automatically skips TTC files** - Prevents errors

**Supported Font Formats**:
| Format | Support | Description |
|--------|---------|-------------|
| CIDFont | ✅ Recommended | Built-in to PDF readers |
| OTF | ✅ Supported | OpenType fonts |
| TTF | ✅ Supported | TrueType fonts |
| TTC | ❌ Not supported | TrueType Collection, causes errors |

### Font Selection Rules

The system automatically selects fonts based on text content:
- **Chinese characters** → STSong-Light (宋体 CIDFont, PDF built-in)
- **English text and numbers** → Times-Roman (新罗马, PDF built-in)

**Important**: Both fonts are built into PDF readers - no font files needed!

### Register Fonts

```python
import sys
sys.path.append('scripts')
from register_fonts import register_chinese_fonts, get_chinese_font_name, get_english_font_name

# Register all available fonts
# Priority: CIDFont (STSong-Light) > TTF fonts
registered = register_chinese_fonts()

# Get recommended fonts
chinese_font = get_chinese_font_name()  # STSong-Light (CIDFont, PDF built-in)
english_font = get_english_font_name()  # Times-Roman (PDF built-in)
print(f"Chinese font: {chinese_font}")
print(f"English font: {english_font}")
```

**Note**: Both fonts are PDF built-in fonts, no font files needed!

### Using Fonts in PDF Creation

#### With reportlab (Built-in Fonts - Recommended)

```python
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.cidfonts import UnicodeCIDFont

# Register CIDFont for Chinese (no font file needed!)
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))

# Create document with proper margins
doc = SimpleDocTemplate("output.pdf", pagesize=letter,
                       rightMargin=2*cm, leftMargin=2*cm,
                       topMargin=2*cm, bottomMargin=2*cm)

# Create styles
styles = getSampleStyleSheet()
body_style = ParagraphStyle(
    'CustomBody',
    parent=styles['Normal'],
    fontN
agent-stream-nesting-logicSkill

万悟平台 SSE 子会话递归嵌套与三明治序列渲染架构指南。涵盖 parentId 领养、order 绝对排序、动静 Chunk 分层及 Vue 2 响应式引用协议。

algorithmic-artSkill

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.

brand-guidelinesSkill

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

canvas-designSkill

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.

claude-apiSkill

Build apps with the Claude API or Anthropic SDK. TRIGGER when: code imports `anthropic`/`@anthropic-ai/sdk`/`claude_agent_sdk`, or user asks to use Claude API, Anthropic SDKs, or Agent SDK. DO NOT TRIGGER when: code imports `openai`/other AI SDK, general programming, or ML/data-science tasks.

doc-coauthoringSkill

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

docxSkill

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

frontend-designSkill

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.