它能做什么
这项技能帮助处理常见的 PDF 任务。适合需要读取、制作或将多个 PDF 合并为一个文件的任何人。
适用场景
- ✓当你希望智能体读取或总结 PDF 文件的文字时。
- ✓当你需要把多份 PDF 文档合并为一个文件时。
- ✓当你想从一份书面文档或网页创建 PDF 时。
技能链接
https://github.com/shareAI-lab/learn-claude-code/blob/main/skills/pdf/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请读取这份 PDF 合同,并提取付款条款部分的文字。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体使用常见的 PDF 工具从文件中提取文字,并使用其他工具从 Markdown、HTML 或代码制作新的 PDF。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PDF Processing Skill
You now have expertise in PDF manipulation. Follow these workflows:
Reading PDFs
Option 1: Quick text extraction (preferred)
# 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
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)
# 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
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
# Using wkhtmltopdf
wkhtmltopdf input.html output.pdf
# Or with Python
python3 -c "
import pdfkit
pdfkit.from_file('input.html', 'output.pdf')
"
Merging PDFs
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
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
- Always check if tools are installed before using them
- Handle encoding issues - PDFs may contain various character encodings
- Large PDFs: Process page by page to avoid memory issues
- OCR for scanned PDFs: Use
pytesseractif text extraction returns empty
常见问题
它能合并 PDF 文件吗?
可以。这项技能包含将多个 PDF 文件合并为一个的方法。
需要安装哪些工具?
根据所用方法的不同,有些选项需要 poppler、pandoc 或 wkhtmltopdf 等工具。
它能从网页创建 PDF 吗?
可以。它可以使用 wkhtmltopdf 将 HTML 转换为 PDF。
详情
作者的原始描述
Process PDF files - extract text, create PDFs, merge documents. Use when user asks to read PDF, create PDF, or work with PDF files.
热度
- GitHub 星标
- 80k
- 排名
- #1718
- 许可证
- MIT
- 更新时间
- 2026/10/27
评论
- …