bitcjm/workbuddy-skills/pdfkit-py

Claude Code and agent skill by bitcjm/workbuddy-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Pure-Python PDF toolkit with 50 commands covering reading, editing, conversion, forms, encryption, OCR, and IR. Trigger on: PDF 阅读, 编辑, 转换, 合并, 拆分, 加密, 签名, OCR, 表单, 水印, 书签, 压缩, 裁剪, 旋转, pdfkit.

Install

npx vskill@latest install bitcjm/workbuddy-skills/pdfkit-py

SKILL.md

pdfkit — AI 原生 PDF 处理工具

你是 pdfkit 的使用专家。用户描述 PDF 处理需求时,你负责选择正确的命令、参数并执行。

⚠️ 环境初始化(看到本段请立即执行)

立即运行以下命令完成环境初始化,不要跳过,不要先检查。

根据操作系统选择:

  • macOS / Linux:

``bash bash ./scripts/setup.sh ``

  • Windows(PowerShell):

``powershell cmd /c ".\scripts\setup.bat" ``

脚本会自动检测 Python 3.10+,如果系统未安装会自动下载独立 Python 运行时(无需管理员权限)。 如果失败,向用户报告错误。成功后本段会被自动删除。

<!-- END_SETUP -->

定位 CLI

skill 加载时会提供 base directory,CLI 入口在 ./scripts/pdfkit.py。

根据操作系统,venv 中的 Python 路径不同:

  • macOS / Linux:<basedir>/scripts/venv/bin/python3
  • Windows:<basedir>\scripts\venv\Scripts\python.exe
bash
# macOS / Linux
/path/to/pdfkit-py/scripts/venv/bin/python3 /path/to/pdfkit-py/scripts/pdfkit.py help
# Windows(PowerShell)—— 必须用 & 调用运算符
& "\path\to\pdfkit-py\scripts\venv\Scripts\python.exe" "\path\to\pdfkit-py\scripts\pdfkit.py" help

所有命令用 base directory 拼上对应平台的 venv python 路径和 scripts/pdfkit.py 的绝对路径调用。 简写为 pdfkit.py <command> 时,实际执行的是上述完整路径。

Windows PowerShell 注意事项
  1. 必须使用 `&`(调用运算符):PowerShell 中执行带引号路径的程序时,必须在最前面加 &,否则会报 UnexpectedToken 错误。
  2. JSON 参数中的引号:PowerShell 中 JSON 参数不能用单引号包裹(单引号在 PowerShell 中是字面字符串,但嵌套双引号仍需转义)。推荐将复杂 JSON 写入文件后用 --config 传入。
  3. 如果 venv 不存在:先运行 .\scripts\setup.bat 初始化环境。
powershell
# ✅ 正确的 Windows PowerShell 调用方式
& "C:\Users\xxx\.codebuddy\skills\pdfkit-py\scripts\venv\Scripts\python.exe" "C:\Users\xxx\.codebuddy\skills\pdfkit-py\scripts\pdfkit.py" split --input "D:\docs\file.pdf" --output_dir "D:\docs\output" --mode ranges --ranges "[[0,2]]"
# ❌ 错误:没有 & 运算符
"C:\...\python.exe" "C:\...\pdfkit.py" split ...

参数不确定时:运行 pdfkit.py <command> help 查看完整参数说明。

字体

字体由 font_manager 模块自动管理,无需手动指定:

  • 内置 NotoSansSC-Regular 字体,在 setup 时自动从 CDN 下载到 <basedir>/fonts/
  • 内置字体主要覆盖简体中文 + 常用 CJK,不要假设它能覆盖所有语言、emoji、特殊符号或罕见字形
  • 内置字体不存在时,自动搜索本机系统字体(macOS: PingFang/STHeiti, Linux: NotoSansCJK/wqy, Windows: 微软雅黑/宋体)
  • 搜索结果缓存,不会重复扫描
  • 用户通过 --font_path 指定时,使用用户指定的
字体处理规则
  • 如果用户明确提到字体、字形、乱码、缺字、显示不对、英文/其他语言不显示、emoji/符号显示异常等问题,不要默认继续使用内置字体
  • 这类场景下,优先去本机系统里搜索能覆盖目标文本的字体,再用该字体重试
  • 如果自动选择的字体显示仍异常,继续换本机其他候选字体,而不是直接告诉用户“字体不支持”
  • 只有在本机确实找不到可用字体时,才向用户说明缺少对应字形覆盖

用户输入

$ARGUMENTS

如果用户未提供具体参数,先问:需要处理哪个 PDF 文件?要做什么操作?

全局选项

Flag说明
--config <file.json>从 JSON 文件加载复杂参数(CLI 参数优先级高于 config 文件)

输出格式统一为 JSON:{"ok": true, "data": {...}} / {"ok": false, "error": "..."}

页码从 0 开始:用户说"第 1 页"→ 参数 0。

坐标系规范

所有命令统一使用 PyMuPDF 坐标系:

  • 原点:页面左上角 (0, 0)
  • x 轴:向右增大
  • y 轴:向下增大
  • 左上角:约 (30, 30)
  • 左下角:约 (30, 页面高度 - 30)
  • 右下角:约 (页面宽度 - 30, 页面高度 - 30)
  • A4 页面尺寸:宽 595,高 842(单位:点)
⚠️ 注意:这与 PDF 原生坐标系(y=0 在底部)相反。所有命令内部已自动处理转换,用户只需按上述规范传入坐标。
唯一例外:form_fill_annotation 的 entry_bounding_box 在 coordinate_type="pdf" 时仍使用 PDF 原生坐标系(y=0 在底部),因为其坐标通常来自外部表单检测工具。

可选依赖

核心依赖在 setup 脚本首次运行时已安装。以下依赖按需安装——当命令执行报错提示缺少某个包时,你应该自动用 venv 内的 pip 安装它,然后重试原命令,不要把安装指引丢给用户。

Python 可选包

pip 路径:

  • macOS / Linux:./scripts/venv/bin/pip install <包名>
  • Windows:.\scripts\venv\Scripts\pip.exe install <包名>
包名涉及命令安装命令
camelot-py[cv]extract_table(lattice/stream 方法)pip install "camelot-py[cv]"
tabula-pyextract_table(tabula 方法)pip install tabula-py
pdf2docxpdf_to_word(pdf2docx 方法)pip install pdf2docx
pikepdfcompress(高级压缩优化)pip install pikepdf
pix2texformula_detect(model 方法)pip install pix2tex

安装流程:执行命令 → 报错含 ModuleNotFoundError 或 ImportError → 用 venv pip 安装对应包 → 重试原命令。

系统外部工具

无需预装。当命令执行报错提示缺少以下工具时,你应该自动执行对应的安装命令,安装完成后重试原命令,不要把安装指引丢给用户,也不要先反问用户要不要安装。

工具用途涉及命令macOS 安装Windows 安装Linux 安装
gsPDF 压缩compressbrew install ghostscriptwinget install ArtifexSoftware.GhostScript --accept-package-agreements --accept-source-agreementssudo apt install -y ghostscript
tesseractOCR 识别smart_edit, edit_scanned, ocr_locate, search_text, extract_textbrew install tesseractwinget install UB-Mannheim.TesseractOCR --accept-package-agreements --accept-source-agreementssudo apt install -y tesseract-ocr
tesseract-langOCR 中文语言包同上(涉及中文 PDF 时需要)brew install tesseract-lang安装 tesseract 时已包含sudo apt install -y tesseract-ocr-chi-sim
soffice格式转换convert, pdf_to_wordbrew install --cask libreofficewinget install TheDocumentFoundation.LibreOffice --accept-package-agreements --accept-source-agreementssudo apt install -y libreoffice

安装流程:执行命令 → 报错含"未找到 xxx 命令"或"语言包缺失" → 根据当前 OS 执行上表对应安装命令 → 重试原命令。

OCR 特别规则:

  • 只要用户意图是编辑扫描件、OCR 定位、OCR 搜索、扫描件提取文本,且命令报缺少 tesseract 或语言包,就直接安装,不要询问用户是否安装
  • 对应命令包括:smart_edit(扫描件路径)、edit_scanned、ocr_locate、search_text --engine ocr、extract_text --ocr_fallback
  • 用户说“修改扫描件”“改图片里的字”“识别扫描 PDF”“OCR 找字”时,默认视为允许安装 OCR 依赖
  • 只有安装命令本身失败、缺少管理员权限、或系统包管理器不可用时,才向用户报告阻塞点

命令详解(50 个命令)

阅读与分析 (13)

page_count — 获取 PDF 页数
bash
pdfkit.py page_count --input doc.pdf
Flag说明
--input必填 输入 PDF 路径
extract_text — 提取文本
💡 支持自动 OCR 降级:添加 --ocr_fallback 参数后,纯扫描件页面(完全无文字层)会自动使用 OCR 提取文字。
混合型页面(有文字层 + 嵌入图片)仅提取文字层文本,图片上的文字不会被 OCR 提取。
不加 --ocr_fallback 时,扫描件页面会返回空并给出提示。
bash
# 基本用法(仅提取文字层)
pdfkit.py extract_text --input doc.pdf --pages '[0,1]'
# 自动 OCR 降级(推荐:一次调用覆盖所有场景)
pdfkit.py extract_text --input scan.pdf --pages '[0]' --ocr_fallback
# 指定输出格式
pdfkit.py extract_text --input doc.pdf --format html --output /tmp/out.html
Flag说明
--input必填 输入 PDF 路径
--pages页码列表 JSON,如 [0,1,3]
--output输出文件路径
--format输出格式,默认 text。可选 text / dict / blocks / words / html
--ocr_fallback自动 OCR 降级,默认 False。仅对纯扫描件页面(无文字层)自动 OCR,混合型页面中图片上的文字不提取(需要 tesseract)
--langOCR 语言,默认 eng+chi_sim(仅 --ocr_fallback 时生效)
to_images — 页面转图片
bash
pdfkit.py to_images --input doc.pdf --output_dir /tmp/imgs/ --dpi 300
Flag说明
--input必填 输入 PDF 路径
--output_dir必填 输出目录
--pages页码列表 JSON
--dpi分辨率,默认 150
--format图片格式,默认 png。可选 png / jpeg
long_image — 多页拼接长图
bash
pdfkit.py long_image --input doc.pdf --output /tmp/long.png
pdfkit.py long_image --input doc.pdf --output /tmp/long.png --pages '[0,1,2]' --gap 10
Flag说明
--input必填 输入 PDF 路径
--output必填 输出图片路径
--pages页码列表 JSON
--dpi分辨率,默认 150
--gap页间距像素,默认 0
extract_images — 提取内嵌图片
bash
pdfkit.py extract_images --input doc.pdf --output_dir /tmp/imgs/
Flag说明
--input必填 输入 PDF 路径
--output_dir必填 输出目录
--pages页码列表 JSON
--min_size最小尺寸(像素),默认 100
extract_table — 提取表格
bash
pdfkit.py extract_table --input doc.pdf --format markdown
pdfkit.py extract_table --input doc.pdf --pages '[0]' --format csv --output /tmp/table.csv
Flag说明
--input必填 输入 PDF 路径
--pages页码列表 JSON
--format输出格式,默认 json。可选 csv / json / markdown
--output输出文件路径
--method提取方法,默认 auto。可选 auto / lattice / stream
--header是否将第一行作为表头,默认 False(原样输出所有行)。有表头行的表格传 --header
layout_analyze
bash
pdfkit.py layout_analyze --input doc.pdf --pages '[0]' --detail full
Flag说明
--input必填 输入 PDF 路径
--pages页码列表 JSON
--detail详细程度,默认 basic。可选 basic / full
ocr_locate — OCR 定位文字
需要 tesseract
bash
pdfkit.py ocr_locate --input scan.pdf --page 0 --text "合同编号"
Flag说明
--input必填 输入 PDF 路径
--page页码,默认 0
--text要定位的文字
--langOCR 语言,默认 eng+chi_sim
chat_pdf — PDF 问答上下文提取
bash
pdfkit.py chat_pdf --input doc.pdf --question "主要结论是什么"
Flag说明
--input必填 输入 PDF 路径
--question问题
--pages页码列表 JSON
--max_context_chars最大上下文字数,默认 8000
chunk_pdf — 文档分块
bash
pdfkit.py chunk_pdf --input doc.pdf --strategy paragraph
pdfkit.py chunk_pdf --input doc.pdf --strategy fixed --chunk_size 500 --overlap 100
Flag说明
--input必填 输入 PDF 路径
--strategy分块策略,默认 paragraph。可选 page / paragraph / fixed / semantic
--chunk_size块大小,默认 1000
--overlap重叠字数,默认 200
--pages页码列表 JSON
formula_detect — 数学公式检测
bash
pdfkit.py formula_detect --input paper.pdf --pages '[0,1]'
Flag说明
--input必填 输入 PDF 路径
--pages页码列表 JSON
--method检测方法,默认 heuristic。可选 heuristic / model
reading_order — 阅读顺序检测
bash
pdfkit.py reading_order --input doc.pdf --pages '[0]'
Flag说明
--input必填 输入 PDF 路径
--pages页码列表 JSON
schema_extract — Schema 结构化提取
bash
pdfkit.py schema_extract --input invoice.pdf \
--schema '{"invoice_no":"string","date":"string","items":[{"name":"string","amount":"number"}]}'
Flag说明
--input必填 输入 PDF 路径
--schema必填 目标结构 JSON
--pages页码列表 JSON

编辑与修改 (10)

smart_edit — 智能编辑(自动判断文字层/扫描件)
bash
# 替换文本(所有页)
pdfkit.py smart_edit --input doc.pdf --output out.pdf \
--edits '[{"type":"replace_text","find":"旧文本","replace":"新文本","page":-1}]'
# 添加文本
pdfkit.py smart_edit --input doc.pdf --output out.pdf \
--edits '[{"type":"add_text","text":"新文本","x":100,"y":200,"page":0}]'
# 预览模式
pdfkit.py smart_edit --input doc.pdf --output out.pdf --dry_run \
--edits '[{"type":"replace_text","find":"旧","replace":"新"}]'
Flag说明
--input必填 输入 PDF 路径
--output必填 输出 PDF 路径
--edits必填 编辑操作列表 JSON
--dry_run预览模式,不实际修改,默认 False

edits 支持的操作类型:

type字段
replace_textfind, replace, page(-1=所有页),color(可选,[r,g,b] 0-1 范围)
add_texttext, x, y(坐标原点在页面左上角,y 向下增大;左上角≈y:30,左下角≈y:页高-30), page, font_size(默认12), color(可选,[r,g,b] 0-1 范围,如红色 [1,0,0])
delete_textfind, page
replace_imagepage, image_index, new_image(图片路径)
pymupdf_edit — 文字层文本编辑
bash
pdfkit.py pymupdf_edit --input doc.pdf --output out.pdf \
--edits '[{"find":"旧","replace":"新","page":0}]'
Flag说明
--input必填 输入 PDF 路径
--output必填 输出 PDF 路径
--edits必填 编辑操作列表 JSON
edit_scanned — 扫描件编辑
需要 tesseract
bash
pdfkit.py edit_scanned --input scan.pdf --output out.pdf \
--page 0 --find "旧文本" --replace "新文本" --font fonts/DroidSansFallback.ttf
Flag说明
--input必填 输入 PDF 路径
--output必填 输出 PDF 路径
--page页码,默认 0
--find必填 查找文本
--replace必填 替换文本
--font字体路径(中文需指定)
--langOCR 语言,默认 eng+chi_sim
search_text — 文本搜索
bash
pdfkit.py search_text --input doc.pdf --find "关键词"
pdfkit.py search_text --input doc.pdf --find "关键词" --page 0 --engine fuzzy
Flag说明
--input必填 输入 PDF 路径
--find必填 搜索文本
--page页码,默认 -1(全部页)
--engine搜索引擎,默认 auto。可选 pymupdf / pdfplumber / fuzzy / ocr / auto
overlay_text — 文本覆盖
bash
pdfkit.py overlay_text --input doc.pdf --output out.pdf \
--overlays '[{"page":0,"bbox":[100,30,300,60],"text":"覆盖文本","font_size":12}]'
Flag说明
--input必填 输入 PDF 路径
--output必填 输出 PDF 路径
--overlays必填 覆盖配置列表 JSON [{page, bbox, text, font_size, color, bg_color}]。bbox 格式 [x0,y0,x1,y1] 使用统一坐标系(左上角原点,y↓)
pdf_create — 创建 PDF

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/bitcjm/workbuddy-skills/pdfkit-py/badge)](https://verified-skill.com/skills/bitcjm/workbuddy-skills/pdfkit-py)

Something wrong with this skill or its page? Tell us.