pdf-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF Skill

PDF 技能

Purpose

用途

Provides expertise in programmatic PDF generation, parsing, and manipulation. Specializes in creating PDFs from scratch, extracting content, merging/splitting documents, and handling forms using PDFKit, PDF.js, Puppeteer, and similar tools.
提供程序化PDF生成、解析和处理的专业能力。擅长使用PDFKit、PDF.js、Puppeteer及同类工具从零创建PDF、提取内容、合并/拆分文档以及处理表单。

When to Use

适用场景

  • Generating PDFs programmatically
  • Extracting text or data from PDFs
  • Merging or splitting PDF documents
  • Filling PDF forms programmatically
  • Converting HTML to PDF
  • Adding watermarks or annotations
  • Parsing PDF structure and metadata
  • Building PDF report generators
  • 程序化生成PDF
  • 从PDF中提取文本或数据
  • 合并或拆分PDF文档
  • 程序化填写PDF表单
  • 将HTML转换为PDF
  • 添加水印或注释
  • 解析PDF结构和元数据
  • 构建PDF报告生成器

Quick Start

快速入门

Invoke this skill when:
  • Generating PDFs from code or data
  • Extracting content from PDF files
  • Merging, splitting, or manipulating PDFs
  • Filling or creating PDF forms
  • Converting HTML/web pages to PDF
Do NOT invoke when:
  • Word document creation → use
    /docx-skill
  • Excel/spreadsheet work → use
    /xlsx-skill
  • PowerPoint creation → use
    /pptx-skill
  • General file operations → use Bash or file tools
在以下场景调用此技能:
  • 从代码或数据生成PDF
  • 从PDF文件提取内容
  • 合并、拆分或处理PDF
  • 填写或创建PDF表单
  • 将HTML/网页转换为PDF
请勿在以下场景调用:
  • 创建Word文档 → 使用
    /docx-skill
  • Excel/电子表格处理 → 使用
    /xlsx-skill
  • 创建PowerPoint → 使用
    /pptx-skill
  • 常规文件操作 → 使用Bash或文件工具

Decision Framework

决策框架

PDF Operation?
├── Generate from scratch
│   ├── Simple → PDFKit (Node) / ReportLab (Python)
│   └── Complex layouts → Puppeteer/Playwright + HTML
├── Parse/Extract
│   ├── Text extraction → pdf-parse / PyPDF2
│   └── Table extraction → Camelot / Tabula
├── Manipulate
│   └── pdf-lib (merge, split, edit)
└── Forms
    └── pdf-lib (fill) / PDFtk (advanced)
PDF Operation?
├── Generate from scratch
│   ├── Simple → PDFKit (Node) / ReportLab (Python)
│   └── Complex layouts → Puppeteer/Playwright + HTML
├── Parse/Extract
│   ├── Text extraction → pdf-parse / PyPDF2
│   └── Table extraction → Camelot / Tabula
├── Manipulate
│   └── pdf-lib (merge, split, edit)
└── Forms
    └── pdf-lib (fill) / PDFtk (advanced)

Core Workflows

核心工作流

1. PDF Generation with PDFKit

1. 使用PDFKit生成PDF

  1. Install PDFKit (
    npm install pdfkit
    )
  2. Create new PDDocument
  3. Add content (text, images, graphics)
  4. Style with fonts and colors
  5. Add pages as needed
  6. Pipe to file or response
  1. 安装PDFKit(
    npm install pdfkit
  2. 创建新的PDDocument
  3. 添加内容(文本、图片、图形)
  4. 设置字体和颜色样式
  5. 根据需要添加页面
  6. 输出到文件或响应

2. HTML to PDF Conversion

2. HTML转PDF

  1. Set up Puppeteer/Playwright
  2. Navigate to HTML content or URL
  3. Configure page size and margins
  4. Set print options (headers, footers)
  5. Generate PDF buffer
  6. Save or stream result
  1. 配置Puppeteer/Playwright
  2. 加载HTML内容或URL
  3. 配置页面尺寸和边距
  4. 设置打印选项(页眉、页脚)
  5. 生成PDF缓冲区
  6. 保存或流式输出结果

3. PDF Parsing and Extraction

3. PDF解析与提取

  1. Choose parser (pdf-parse, PyPDF2, pdfplumber)
  2. Load PDF file
  3. Extract text or structured data
  4. Handle multi-page documents
  5. Clean and normalize extracted text
  6. Output in desired format
  1. 选择解析器(pdf-parse、PyPDF2、pdfplumber)
  2. 加载PDF文件
  3. 提取文本或结构化数据
  4. 处理多页文档
  5. 清理并标准化提取的文本
  6. 以所需格式输出

Best Practices

最佳实践

  • Use vector graphics over raster when possible
  • Embed fonts for consistent rendering
  • Test PDF output across different readers
  • Handle large PDFs with streaming
  • Use appropriate library for task complexity
  • Consider accessibility (tagged PDFs)
  • 尽可能使用矢量图形而非栅格图形
  • 嵌入字体以确保渲染一致性
  • 在不同阅读器中测试PDF输出
  • 使用流式处理大型PDF
  • 根据任务复杂度选择合适的库
  • 考虑可访问性(带标签的PDF)

Anti-Patterns

反模式

Anti-PatternProblemCorrect Approach
Image-only PDFsNot searchable/accessibleUse text with fonts
No font embeddingRendering issuesEmbed required fonts
Memory loading large PDFsCrashesStream processing
Ignoring encryptionSecurity/access issuesHandle encrypted PDFs
Wrong tool for jobOver-engineeringMatch tool to complexity
反模式问题正确做法
纯图片PDF无法搜索/访问使用带字体的文本
未嵌入字体渲染问题嵌入所需字体
内存加载大型PDF崩溃流式处理
忽略加密安全/访问问题处理加密PDF
工具选择不当过度设计根据复杂度匹配工具