pdf 精选
当用户需要对PDF文件进行任何操作时,请使用此技能。包括从 PDF 中读取或提取文本/表格、合并多个 PDF、拆分 PDF、旋转页面、添加水印、创建新PDF、填写PDF表单、加密/解密 PDF、提取图片,以及对扫描版 PDF 进行 OCR 使其可搜索。如果用户提到 .pdf 文件或要求生成 PDF,请使用此技能。
安装方式
cp -r src/qwenpaw/agents/skills/pdf-zh ~/.claude/skills/pdf-zh把该 skill 目录放进客户端 skills 目录。不同客户端的目录可能不同,Claude Code 默认是 ~/.claude/skills/
https://raw.githubusercontent.com/agentscope-ai/QwenPaw/02b6a6d088e37192934645cbc0876114bb9e98ae/src/qwenpaw/agents/skills/pdf-zh/SKILL.md下载后另存为 ~/.claude/skills/pdf-zh/SKILL.md。链接锁定采集时的 commit,内容与本站展示一致。
整仓一次性获取:git clone --depth 1 https://github.com/agentscope-ai/QwenPaw.git
依赖与权限
- 无需 API Key
- 无需联网
- 依赖外部命令:
pythonpippdftkqpdf - 以上为按正文与 frontmatter 自动推断的信号,仅供参考;安装前建议先阅读原文。
SKILL.md 正文
重要: 所有 scripts/ 路径均相对于此技能目录。
运行方式:cd {this_skill_dir} && python scripts/...
或使用execute_shell_command的cwd参数。
PDF 处理指南
前置要求
- pypdf:核心 PDF 读写功能
- pdfplumber:文本和表格提取
- reportlab:PDF 创建
- pdftotext (poppler-utils):命令行文本提取
- pdftoppm (poppler-utils):PDF 转图片
- qpdf:PDF 操作(合并、拆分、旋转、解密)
概述
本指南涵盖了使用 Python 库和命令行工具进行 PDF 处理的基本操作。有关高级功能、JavaScript 库和详细示例,请参阅 REFERENCE.md。如果需要填写 PDF 表单,请阅读 FORMS.md 并按照其中的说明操作。
快速入门
from pypdf import PdfReader, PdfWriter
# 读取 PDF
reader = PdfReader("document.pdf")
print(f"Pages: {len(reader.pages)}")
# 提取文本
text = ""
for page in reader.pages:
text += page.extract_text()
Python 库
pypdf - 基本操作
合并 PDF
from pypdf import PdfWriter, PdfReader
writer = PdfWriter()
for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]:
reader = PdfReader(pdf_file)
for page in reader.pages:
writer.add_page(page)
with open("merged.pdf", "wb") as output:
writer.write(output)
拆分 PDF
reader = PdfReader("input.pdf")
for i, page in enumerate(reader.pages):
writer = PdfWriter()
writer.add_page(page)
with open(f"page_{i+1}.pdf", "wb") as output:
writer.write(output)
提取元数据
reader = PdfReader("document.pdf")
meta = reader.metadata
print(f"Title: {meta.title}")
print(f"Author: {meta.author}")
print(f"Subject: {meta.subject}")
print(f"Creator: {meta.creator}")
旋转页面
reader = PdfReader("input.pdf")
writer = PdfWriter()
page = reader.pages[0]
page.rotate(90) # 顺时针旋转 90 度
writer.add_page(page)
with open("rotated.pdf", "wb") as output:
writer.write(output)
pdfplumber - 文本和表格提取
提取带布局的文本
import pdfplumber
with pdfplumber.open("document.pdf") as pdf:
for page in pdf.pages:
text = page.extract_text()
print(text)
提取表格
with pdfplumber.open("document.pdf") as pdf:
for i, page in enumerate(pdf.pages):
tables = page.extract_tables()
for j, table in enumerate(tables):
print(f"Table {j+1} on page {i+1}:")
for row in table:
print(row)
高级表格提取
import pandas as pd
with pdfplumber.open("document.pdf") as pdf:
all_tables = []
for page in pdf.pages:
tables = page.extract_tables()
for table in tables:
if table: # 检查表格是否为空
df = pd.DataFrame(table[1:], columns=table[0])
all_tables.append(df)
# 合并所有表格
if all_tables:
combined_df = pd.concat(all_tables, ignore_index=True)
combined_df.to_excel("extracted_tables.xlsx", index=False)
reportlab - 创建 PDF
基本 PDF 创建
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("hello.pdf", pagesize=letter)
width, height = letter
# 添加文本
c.drawString(100, height - 100, "Hello World!")
c.drawString(100, height - 120, "This is a PDF created with reportlab")
# 添加线条
c.line(100, height - 140, 400, height - 140)
# 保存
c.save()
创建多页 PDF
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.styles import getSampleStyleSheet
doc = SimpleDocTemplate("report.pdf", pagesize=letter)
styles = getSampleStyleSheet()
story = []
# 添加内容
title = Paragraph("Report Title", styles['Title'])
story.append(title)
story.append(Spacer(1, 12))
body = Paragraph("This is the body of the report. " * 20, styles['Normal'])
story.append(body)
story.append(PageBreak())
# 第 2 页
story.append(Paragraph("Page 2", styles['Heading1']))
story.append(Paragraph("Content for page 2", styles['Normal']))
# 构建 PDF
doc.build(story)
下标和上标
重要:切勿在 ReportLab PDF 中使用 Unicode 下标/上标字符(₀₁₂₃₄₅₆₇₈₉、⁰¹²³⁴⁵⁶⁷⁸⁹)。内置字体不包含这些字形,会导致它们渲染为黑色方块。
请改用 ReportLab 在 Paragraph 对象中的 XML 标记标签:
from reportlab.platypus import Paragraph
from reportlab.lib.styles import getSampleStyleSheet
styles = getSampleStyleSheet()
# 下标:使用 <sub> 标签
chemical = Paragraph("H<sub>2</sub>O", styles['Normal'])
# 上标:使用 <super> 标签
squared = Paragraph("x<super>2</super> + y<super>2</super>", styles['Normal'])
对于使用 canvas 绘制的文本(非 Paragraph 对象),请手动调整字体大小和位置,而不是使用 Unicode 下标/上标。
命令行工具
pdftotext (poppler-utils)
# 提取文本
pdftotext input.pdf output.txt
# 保留布局提取文本
pdftotext -layout input.pdf output.txt
# 提取指定页面
pdftotext -f 1 -l 5 input.pdf output.txt # 第 1-5 页
qpdf
# 合并 PDF
qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf
# 拆分页面
qpdf input.pdf --pages . 1-5 -- pages1-5.pdf
qpdf input.pdf --pages . 6-10 -- pages6-10.pdf
# 旋转页面
qpdf input.pdf output.pdf --rotate=+90:1 # 将第 1 页旋转 90 度
# 移除密码
qpdf --password=mypassword --decrypt encrypted.pdf decrypted.pdf
pdftk(如果可用)
# 合并
pdftk file1.pdf file2.pdf cat output merged.pdf
# 拆分
pdftk input.pdf burst
# 旋转
pdftk input.pdf rotate 1east output rotated.pdf
常见任务
从扫描版 PDF 提取文本
# 需要安装:pip install pytesseract pdf2image
import pytesseract
from pdf2image import convert_from_path
# 将 PDF 转换为图片
images = convert_from_path('scanned.pdf')
# 对每页进行 OCR
text = ""
for i, image in enumerate(images):
text += f"Page {i+1}:\n"
text += pytesseract.image_to_string(image)
text += "\n\n"
print(text)
添加水印
from pypdf import PdfReader, PdfWriter
# 创建水印(或加载已有水印)
watermark = PdfReader("watermark.pdf").pages[0]
# 应用到所有页面
reader = PdfReader("document.pdf")
writer = PdfWriter()
for page in reader.pages:
page.merge_page(watermark)
writer.add_page(page)
with open("watermarked.pdf", "wb") as output:
writer.write(output)
提取图片
# 使用 pdfimages (poppler-utils)
pdfimages -j input.pdf output_prefix
# 这会将所有图片提取为 output_prefix-000.jpg、output_prefix-001.jpg 等
密码保护
from pypdf import PdfReader, PdfWriter
reader = PdfReader("input.pdf")
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
# 添加密码
writer.encrypt("userpassword", "ownerpassword")
with open("encrypted.pdf", "wb") as output:
writer.write(output)
快速参考
| 任务 | 最佳工具 | 命令/代码 |
|---|---|---|
| 合并 PDF | pypdf | writer.add_page(page) |
| 拆分 PDF | pypdf | 每页一个文件 |
| 提取文本 | pdfplumber | page.extract_text() |
| 提取表格 | pdfplumber | page.extract_tables() |
| 创建 PDF | reportlab | Canvas 或 Platypus |
| 命令行合并 | qpdf | qpdf --empty --pages ... |
| OCR 扫描版 PDF | pytesseract | 先转换为图片 |
| 填写 PDF 表单 | pdf-lib 或 pypdf(见 FORMS.md) | 见 FORMS.md |
后续步骤
- 有关 pypdfium2 的高级用法,请参阅 REFERENCE.md
- 有关 JavaScript 库(pdf-lib),请参阅 REFERENCE.md
- 如果需要填写 PDF 表单,请按照 FORMS.md 中的说明操作
- 有关故障排除指南,请参阅 REFERENCE.md
质量与来源
- 所属仓库
- agentscope-ai/QwenPaw
- 仓库星标
- 3.6 万
- 最近更新
- 今天
- 采集时间
- 今天
- commit
- 02b6a6d088e3
- 内容指纹
- sha256:d81e0d27245f087
- 文件路径
- src/qwenpaw/agents/skills/pdf-zh/SKILL.md
同仓库其它 Skill
查看全部 48 个edu-math-tutorial
数学题分步讲解视频的领域知识。适用场景:(1) 用户给出一道数学题并要求做讲解/ 解题视频;(2) 用户说"讲解这道题"、"生成解题视频"、"make a math tutorial"; (3) 需要中文数学教学视频,涉及方程、公式或几何图形。本 skill 只提供领域 知识(题目拆解、讲解节奏、旁白文案规范、版式与 KaTeX 排版风格);画面、 配音与成片一律用 Creator 原生 Element 与工具从源头构建。
professional-media-prompts
为 Creator 编译制作级视觉资产图、电影分镜图和参考生视频 Prompt。适用于 角色身份板/设定图、关键帧或多宫格分镜、短片动作节拍、R2V/I2V/T2V 提示词, 尤其适合要求角色一致性、镜头语言、参考图职责、Seedance 时间段或声音设计的 任务。不用于纯素材剪辑、只查询模型参数,或只评价已经生成的成片。
visual-asset-design
为角色/场景/道具设计视觉资产、编写或修复 VisualVariant 与阵容图的生成 Prompt 时使用。涵盖参考图布局(艺术身份板/序列关键帧/环境研究板/道具研究 板)、构图与镜头语言、图片审核误判规避、实体 continuity 与以主图为参考 的跨 Variant 衍生设计。不用于视频 Prompt 编译(见 professional-media-prompts)、 纯素材剪辑或只评价已生成产物。
alicloud_cli
阿里云 CLI 中文文档镜像检索与命令辅助:先走章节索引,再下钻正文页面,给出命令前必须有本地文档证据。
terraform-cli-setup
Terraform CLI 安装与初始化技能。当用户本地未安装 Terraform 时自动完成安装,确保 terraform 命令可用并能执行 init/validate。不负责 Provider 凭证配置,凭证在实际使用时由 terraform-skill 引导。
terraform-skill
Use when working with Terraform or OpenTofu - creating modules, writing tests (native test framework, Terratest), setting up CI/CD pipelines, reviewing configurations, choosing between testing approaches, debugging state issues, implementing security scanning (trivy, checkov), or making infrastructure-as-code architecture decisions
相似 Skill
更多「自动化」agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
presentation-structure
Knowledge about the presentation slide format, weight system, navigation, and section structure
presentation-styling
Knowledge about CSS classes, component patterns, and syntax highlighting in the presentation
vibe-to-agentic-framework
The conceptual framework behind the presentation — what "Vibe Coding to Agentic Engineering" means, why the journey is structured the way it is, and how every slide fits the narrative arc
time-skill
Display the current time in Pakistan Standard Time (PKT, UTC+5). Use when the user asks for the current time, Pakistan time, or PKT.
weather-fetcher
Instructions for fetching current weather temperature data for Dubai, UAE from Open-Meteo API