它能做什么
这项技能帮助 AI 制作和编辑 PDF 文件。适合需要报告、表单、合并文档或受保护 PDF 的人。
适用场景
- ✓当你要求制作 PDF 报告、信函或摘要时。
- ✓当你需要填写、合并、拆分或为现有 PDF 添加水印时。
- ✓当你需要可填写的表单,或使用自定义字体或精确版面的 PDF 的时候。
技能链接
https://github.com/spinabot/brigade/blob/main/skills/pdf/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把这三份 PDF 合同合并为一个文件,并在每一页上添加 DRAFT 水印。”
每周 5 个新技能,1 分钟读完。
工作原理
对于基础文档,AI 使用简单的生成工具;对于现有 PDF,则使用编辑工具。对于较复杂的工作,它会编写脚本来绘制版面、嵌入字体并创建表单字段。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
pdf — professional PDFs
| Need | Path |
|---|---|
| Simple content PDF (title, headings, paragraphs, image) | Path 1 — make_document tool |
| Fill an existing form, merge/split/stamp/watermark | Path 2 — edit_document tool |
| Form-field CREATION, vector drawing, embedded fonts (bold/CJK), precise layout, encryption, page surgery | Path 3 — script @cantoo/pdf-lib via brigade exec-node |
| Pixel-perfect, brand-styled layout from HTML/CSS | Path 4 — HTML→PDF (optional binary) |
Note: PDF is a final format with no reflow engine. If the recipient must edit, deliver the editable source (
.docx/.xlsx) and the PDF.
Path 1 — quick content PDF (make_document tool)
make_document(format="pdf", content={ title, pages:[{ heading, paragraphs, image:{path} }] })
Flow layout, US-Letter, single column, word-wrapped. Good for reports/summaries/letters. For forms, precise layout, or custom fonts → Path 3.
Path 2 — edit an existing PDF (edit_document tool)
fill_form {fields}— fill existing AcroForm fields by name (text/checkbox/dropdown).merge {pdfs}/add_pages {pdfs}·split {pages}·remove_pages {pages}.stamp {text}·watermark {text}(45° translucent).
Form decision: first detect whether the PDF has real fillable fields. If it does → fill them (clean, type-validated). If it's a flat/scanned form (no fields) → you must draw text at coordinates instead (Path 3, annotations) — never assume fields exist.
Path 3 — full power: script @cantoo/pdf-lib
Brigade bundles @cantoo/pdf-lib (a maintained pdf-lib fork — note the scoped name) plus @pdf-lib/fontkit (custom-font embedding) and unpdf (text extraction). write a gen.cjs, run brigade exec-node gen.cjs:
// gen.cjs — illustrative
const fs = require("node:fs");
const { PDFDocument, StandardFonts, rgb } = require("@cantoo/pdf-lib");
(async () => {
const pdf = await PDFDocument.create();
// embed a custom font (real bold / CJK / Unicode) — requires fontkit
// const fontkit = require("@pdf-lib/fontkit"); pdf.registerFontkit(fontkit);
// const font = await pdf.embedFont(fs.readFileSync("Brand-Bold.ttf"));
const font = await pdf.embedFont(StandardFonts.HelveticaBold);
const page = pdf.addPage([612, 792]); // US Letter; origin is BOTTOM-LEFT, y-up
page.drawText("Invoice", { x: 54, y: 720, size: 22, font, color: rgb(0.1, 0.1, 0.1) });
page.drawRectangle({ x: 54, y: 700, width: 504, height: 1, color: rgb(0.8, 0.8, 0.8) }); // vector rule
// CREATE fillable form fields
const form = pdf.getForm();
const name = form.createTextField("client.name");
name.addToPage(page, { x: 120, y: 640, width: 300, height: 18 });
const agree = form.createCheckBox("agree");
agree.addToPage(page, { x: 54, y: 600, width: 14, height: 14 });
// form.flatten(); // bake fields into static content if no further filling
fs.writeFileSync(process.argv[2] || "out.pdf", await pdf.save());
console.log("wrote");
})();
@cantoo/pdf-lib covers: draw text/lines/rects/ellipses/SVG paths/images; embed custom TTF/OTF fonts (subset, full Unicode); create AND fill AcroForm text/checkbox/radio/dropdown/option-list fields; flatten; copy/merge/split/rotate pages; metadata; password encryption (the reason this fork is bundled). Extract text/structure with unpdf.
Coordinate gotcha: pdf-lib origin is bottom-left, y-up. If you author field positions from a top-left image/spec, convert: y_pdf = pageHeight - y_top - height. One coordinate convention per script.
Path 4 — pixel-perfect / branded PDF from HTML+CSS (optional)
pdf-lib has no HTML/CSS layout engine — for a designed, brand-styled document, render HTML→PDF. Use whatever is present (detect first):
command -v soffice >/dev/null 2>&1 && soffice --headless --convert-to pdf brand.html # LibreOffice route
A headless browser (Puppeteer/Playwright page.pdf()) is the higher-fidelity alternative if installed. Prefer Path 1/3 unless the brand design genuinely requires CSS.
Conventions
- Use real AcroForm fields when filling a fillable PDF; only fall back to drawn-text annotations for flat/scanned forms.
- Embed a font for anything beyond basic Latin — standard PDF fonts lack bold-as-a-face and all CJK/emoji (missing glyphs render as boxes).
- Keep ≥0.5" margins; align to a grid; don't rely on text reflowing (there's no
常见问题
它可以填写现有的表单吗?
可以。它可以按名称填写现有的表单字段,也可以为更复杂的表单创建新字段。
PDF 之后还能编辑吗?
PDF 没有便于编辑的格式,因此当收件人需要编辑时,该技能建议将可编辑的源文件与 PDF 一起发送。
它可以加密 PDF 吗?
可以。它可以加密 PDF,也可以从 PDF 中提取文字。
详情
作者的原始描述
Create and edit PDFs to a professional standard — generate from content, draw vector/precise layouts, embed custom (incl. CJK/Unicode) fonts, CREATE and fill AcroForm fields (text/checkbox/radio/dropdown), flatten, merge/split/rotate, stamp/watermark, encrypt, and extract text. Use when the user asks Brigade to make a PDF, fill or build a PDF form, or combine/split/stamp/secure PDFs.
repo: spinabot/brigade
热度
- GitHub 星标
- 11k
- 排名
- #11734
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …