$npx -y skills add stvlynn/dingtalk-wukong-skills --skill pdfComprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.
| 1 | # PDF文档处理专家 Real Skill |
| 2 | |
| 3 | ## 一句话说明 |
| 4 | |
| 5 | 全面的 PDF 文档处理工具,支持文本表格提取、PDF 创建、文档操作和表单填写。 |
| 6 | |
| 7 | **PDF Processing Guide** - Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ## 使用场景 |
| 12 | |
| 13 | **适用**: |
| 14 | - 从 PDF 提取文本、表格数据并导出 Excel |
| 15 | - 创建新的 PDF 文档(报告、证书、发票) |
| 16 | - 合并、拆分、旋转 PDF 文档 |
| 17 | - 填写 PDF 表单(政府表单、申请表) |
| 18 | - 批量处理多个 PDF 文件 |
| 19 | |
| 20 | **不适用**: |
| 21 | - 扫描版 PDF(需先 OCR 处理 / requires OCR first) |
| 22 | - 复杂的 PDF 编辑(用专业软件 / use professional software) |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## 核心流程 |
| 27 | |
| 28 | ``` |
| 29 | 用户需求 → 判断任务类型 → 选择工具 → 执行操作 → 验证输出 |
| 30 | User request → Task type classification → Tool selection → Execute → Validate |
| 31 | ``` |
| 32 | |
| 33 | **任务类型判断 (Task Classification)**: |
| 34 | |
| 35 | ### Extracting Data (提取数据) |
| 36 | - **文本提取 (Text extraction)** → pdfplumber.extract_text() |
| 37 | - Better accuracy than pypdf for text extraction |
| 38 | - **表格提取 (Table extraction)** → pdfplumber.extract_tables() + pandas |
| 39 | - Intelligent table structure recognition |
| 40 | - Export to Excel, CSV, JSON |
| 41 | |
| 42 | ### Creating PDFs (创建 PDF) |
| 43 | - **简单文档 (Simple documents)** → reportlab.pdfgen.canvas |
| 44 | - Quick document creation with text and graphics |
| 45 | - **复杂布局 (Complex layouts)** → reportlab.platypus |
| 46 | - Paragraphs, Tables, Images with advanced styling |
| 47 | |
| 48 | ### PDF Operations (PDF 操作) |
| 49 | - **合并 (Merge)** → pypdf.PdfWriter |
| 50 | - Combine multiple PDFs into one |
| 51 | - **拆分 (Split)** → pypdf.PdfWriter (save each page separately) |
| 52 | - **旋转 (Rotate)** → page.rotate() |
| 53 | - **元信息 (Metadata)** → pypdf.PdfReader.metadata / PdfWriter.add_metadata() |
| 54 | |
| 55 | ### Form Processing (表单处理) |
| 56 | - **查看字段 (View fields)** → See forms.md |
| 57 | - **填写表单 (Fill forms)** → See forms.md |
| 58 | - **批量处理 (Batch processing)** → Loop + form filling API |
| 59 | |
| 60 | --- |
| 61 | |
| 62 | ## 任务完成标准 |
| 63 | |
| 64 | **必须满足**(缺一不可): |
| 65 | - PDF 文件可正常打开 |
| 66 | - 提取的数据完整准确 |
| 67 | - 表格结构保留正确(行列对应) |
| 68 | - 创建的 PDF 内容清晰可读 |
| 69 | |
| 70 | **质量评级**: |
| 71 | - ⭐⭐⭐⭐⭐ 优秀 - 数据完整 + 格式规范 + 自动化批处理 |
| 72 | - ⭐⭐⭐ 及格 - 数据正确 + PDF 可用 |
| 73 | - ⭐ 失败 - 数据缺失或 PDF 损坏 |
| 74 | |
| 75 | --- |
| 76 | |
| 77 | ## 参考资料(供 AI 使用) |
| 78 | |
| 79 | | 类型 | 路径 | 说明 | |
| 80 | |-----|------|------| |
| 81 | | 核心文档 | `docs/00-SKILL-完整处理指南.md` | Complete PDF processing guide (~300 lines) | |
| 82 | | 表单处理 | `docs/forms.md` | PDF form filling detailed tutorial | |
| 83 | | 高级参考 | `docs/reference.md` | JavaScript libraries and advanced features | |
| 84 | |
| 85 | --- |
| 86 | |
| 87 | ## 关键原则(AI 必读 / Critical Principles) |
| 88 | |
| 89 | ### 1. Prefer pdfplumber for Extraction (优先使用 pdfplumber) |
| 90 | - **文本提取**: More accurate than pypdf |
| 91 | - **表格识别**: Strong table recognition capability |
| 92 | - **布局保留**: Preserves layout information |
| 93 | - **复杂 PDF**: Better for complex PDF processing |
| 94 | |
| 95 | ### 2. Table Data Normalization (表格数据规范化) |
| 96 | ```python |
| 97 | # Best practice for table extraction |
| 98 | import pdfplumber |
| 99 | import pandas as pd |
| 100 | |
| 101 | all_tables = [] |
| 102 | with pdfplumber.open("document.pdf") as pdf: |
| 103 | for page in pdf.pages: |
| 104 | tables = page.extract_tables() |
| 105 | for table in tables: |
| 106 | if table: # Check not empty |
| 107 | df = pd.DataFrame(table[1:], columns=table[0]) # First row as header |
| 108 | all_tables.append(df) |
| 109 | |
| 110 | # Combine and clean |
| 111 | combined = pd.concat(all_tables, ignore_index=True) |
| 112 | combined.to_excel("output.xlsx", index=False) |
| 113 | ``` |
| 114 | |
| 115 | ### 3. Scanned PDFs Require OCR (扫描版需要 OCR) |
| 116 | - **识别**: If text extraction returns empty or garbled text |
| 117 | - **处理**: Must use OCR tools first (Tesseract, Adobe Acrobat, etc.) |
| 118 | - **告知用户**: Clearly inform user that OCR pre-processing is needed |
| 119 | |
| 120 | ### 4. Memory Management for Large Files (大文件内存管理) |
| 121 | - Batch processing for multiple PDFs |
| 122 | - Process pages sequentially rather than loading entire document |
| 123 | - Use generators when possible |
| 124 | |
| 125 | --- |
| 126 | |
| 127 | ## 快速命令参考 (Quick Commands) |
| 128 | |
| 129 | ### Text Extraction (文本提取) |
| 130 | ```python |
| 131 | import pdfplumber |
| 132 | |
| 133 | with pdfplumber.open("document.pdf") as pdf: |
| 134 | for page in pdf.pages: |
| 135 | text = page.extract_text() |
| 136 | print(text) |
| 137 | ``` |
| 138 | |
| 139 | ### Table to Excel (表格转 Excel) |
| 140 | ```python |
| 141 | import pdfplumber |
| 142 | import pandas as pd |
| 143 | |
| 144 | all_tables = [] |
| 145 | with pdfplumber.open("document.pdf") as pdf: |
| 146 | for page in pdf.pages: |
| 147 | tables = page.extract_tables() |
| 148 | for table in tables: |
| 149 | if table: |
| 150 | df = pd.DataFrame(table[1:], columns=table[0]) |
| 151 | all_tables.append(df) |
| 152 | |
| 153 | combined = pd.concat(all_tables, ignore_index=True) |
| 154 | combined.to_excel("extracted_tables.xlsx", index=False) |
| 155 | ``` |
| 156 | |
| 157 | ### Merge PDFs (合并 PDF) |
| 158 | ```python |
| 159 | from pypdf import PdfWriter, PdfReader |
| 160 | |
| 161 | writer = PdfWriter() |
| 162 | for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]: |
| 163 | reader = PdfReader(pdf_file) |
| 164 | for page in reader.pages: |
| 165 | writer.add_page(page) |
| 166 | |
| 167 | with open("merged.pdf", "wb") as output: |
| 168 | writer.write(output) |
| 169 | ``` |
| 170 | |
| 171 | ### Split PDF (拆分 PDF) |
| 172 | ```python |
| 173 | from pypdf import PdfReader, PdfWriter |
| 174 | |
| 175 | reader = PdfReader("large_document.pdf") |
| 176 | for i, page in enumerate(reader.pages): |
| 177 | writer = PdfWriter() |
| 178 | writer.add_page(page) |
| 179 | with open(f"page_{i+1}.pdf", "wb") as output: |
| 180 | writer.write(output) |
| 181 | ``` |
| 182 | |
| 183 | ### Create PDF (创建 PDF) |
| 184 | `` |