简介
开源 PDFtk 命令行工具,支持合并/拆分/旋转/加密/解密/水印/表单填充等完整 PDF 操作,无网络依赖,适合自动化批处理场景
原始描述
Skill for using the command-line tool pdftk (PDFtk Server) for working with PDF files. Use when asked to merge PDFs, split PDFs, rotate pages, encrypt or dec...
通过你的 Agent 添加
安装目录:pdftk-server/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
PDFtk Server 综合评估
PDFtk Server 是一款历史悠久、功能完备的开源命令行 PDF 处理工具,由 Sid Steward 创建,现由 PDF Labs 维护。作为 PDF 操作领域的经典解决方案,它提供了 PDF 生命周期管理的全栈能力。
核心用法
该工具采用简洁的声明式语法:pdftk [输入文件] [操作] [参数] output [输出文件]。支持文件句柄(A=, B=)实现多源文档操作,内置 20+ 种操作模式。典型工作流包括:使用 cat 合并/提取页面,burst 拆分为单页,rotate 90度增量旋转,encrypt/decrypt 处理密码保护,fill_form 配合 FDF/XFDF 数据填充表单,background/stamp 添加水印/图章,dump_data 提取元数据,shuffle 用于扫描文档的奇偶页交错处理。
显著优点
- 功能完整性:覆盖 PDF 操作的核心需求,从基础页面处理到高级加密、表单、附件管理
- 脚本友好:纯命令行接口,退出码规范,适合 Shell/Batch 自动化集成与 CI/CD 流水线
- 跨平台:原生支持 Windows、macOS、主流 Linux 发行版
- 轻量稳定:无 GUI 依赖,内存占用低,处理大文件表现稳健
- 开源免费:GPL 协议授权,商用友好
潜在局限
- 维护状态:核心开发放缓,部分现代 PDF 特性(如 PDF 2.0、高级 JavaScript 表单)支持有限
- 输出质量:某些操作可能改变 PDF 内部结构,影响文件大小优化
- 表单能力:仅支持 AcroForm,不支持较新的 XFA 动态表单
- 无实时预览:命令行工具需配合文件系统操作,调试成本高于 GUI 方案
适合人群
系统管理员、DevOps 工程师、需要 PDF 批处理自动化的开发者、注重可重复工作流的技术用户。不适合需要所见即所得编辑、复杂排版调整或现代交互式表单设计的场景。
常规风险
- 密码操作需确保
owner_pw与user_pw区分,错误配置可能导致权限失控 flatten操作不可逆,表单数据将固化至页面内容- 加密强度依赖传入参数,默认 128-bit AES 需显式指定更高强度
- 处理敏感文档时需注意 shell 历史记录可能泄露密码参数
技能正文
name: pdftk-server description: 'Skill for using the command-line tool pdftk (PDFtk Server) for working with PDF files. Use when asked to merge PDFs, split PDFs, rotate pages, encrypt or decrypt PDFs, fill PDF forms, apply watermarks, stamp overlays, extract metadata, burst documents into pages, repair corrupted PDFs, attach or extract files, or perform any PDF manipulation from the command line.'
PDFtk Server
PDFtk Server is a command-line tool for working with PDF documents. It can merge, split, rotate, encrypt, decrypt, watermark, stamp, fill forms, extract metadata, and manipulate PDFs in a variety of ways.
When to Use This Skill
- Merging or joining multiple PDF files into one
- Splitting or bursting a PDF into individual pages
- Rotating PDF pages
- Encrypting or decrypting PDF files
- Filling PDF form fields from FDF/XFDF data
- Applying background watermarks or foreground stamps
- Extracting PDF metadata, bookmarks, or form field information
- Repairing corrupted PDF files
- Attaching or extracting files embedded in PDFs
- Removing specific pages from a PDF
- Collating separately scanned even/odd pages
- Compressing or decompressing PDF page streams
Prerequisites
- PDFtk Server must be installed on the system
- Windows: Download and run the installer (see
references/download.md) - macOS:
brew install pdftk-java - Linux (Debian/Ubuntu):
sudo apt-get install pdftk - Linux (Red Hat/Fedora):
sudo dnf install pdftk
- Windows: Download and run the installer (see
- Access to a terminal or command prompt
- Verify installation by running
pdftk --version
Step-by-Step Workflows
Merge Multiple PDFs
pdftk file1.pdf file2.pdf cat output merged.pdf
Using handles for more control:
pdftk A=file1.pdf B=file2.pdf cat A B output merged.pdf
Split a PDF into Individual Pages
pdftk input.pdf burst
Extract Specific Pages
Extract pages 1-5 and 10-15:
pdftk input.pdf cat 1-5 10-15 output extracted.pdf
Remove Specific Pages
Remove page 13:
pdftk input.pdf cat 1-12 14-end output output.pdf
Rotate Pages
Rotate all pages 90 degrees clockwise:
pdftk input.pdf cat 1-endeast output rotated.pdf
Encrypt a PDF
Set an owner password and a user password with 128-bit encryption (default):
pdftk input.pdf output secured.pdf owner_pw mypassword user_pw userpass
Decrypt a PDF
Remove encryption using the known password:
pdftk secured.pdf input_pw mypassword output unsecured.pdf
Fill a PDF Form
Populate form fields from an FDF file and flatten to prevent further edits:
pdftk form.pdf fill_form data.fdf output filled.pdf flatten
Apply a Background Watermark
Place a single-page PDF behind every page of the input (input should have transparency):
pdftk input.pdf background watermark.pdf output watermarked.pdf
Stamp an Overlay
Place a single-page PDF on top of every page of the input:
pdftk input.pdf stamp overlay.pdf output stamped.pdf
Extract Metadata
Export bookmarks, page metrics, and document information:
pdftk input.pdf dump_data output metadata.txt
Repair a Corrupted PDF
Pass a broken PDF through pdftk to attempt automatic repair:
pdftk broken.pdf output fixed.pdf
Collate Scanned Pages
Interleave separately scanned even and odd pages:
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
Troubleshooting
| Issue | Solution |
|---|---|
pdftk command not found |
Verify installation; check that pdftk is in your system PATH |
| Cannot decrypt PDF | Ensure you are providing the correct owner or user password via input_pw |
| Output file is empty or corrupt | Check input file integrity; try running pdftk input.pdf output repaired.pdf first |
| Form fields not visible after fill | Use the flatten flag to merge fields into the page content |
| Watermark not appearing | Ensure the input PDF has transparent regions; use stamp for opaque overlays |
| Permission denied errors | Check file permissions on input and output paths |
References
Bundled reference documents in the references/ folder:
- pdftk-man-page.md - Complete manual reference with all operations, options, and syntax
- pdftk-cli-examples.md - Practical command-line examples for common tasks
- download.md - Installation and download instructions for all platforms
- pdftk-server-license.md - PDFtk Server licensing information
- third-party-materials.md - Third-party library licenses
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。