productivity
高风险
PDFtk Server
用于使用命令行工具 pdftk (PDFtk Server) 处理 PDF 文件的技能。在需要合并、拆分、旋转、加密、解密、填写表单、添加水印、加盖戳记、提取元数据、将 PDF 拆分为单页、修复损坏的 PDF、附加或提取文件或通过命令行执行任何 PDF 操作时使用。
文件预览
6 个文件
references
SKILL.md
4.6 KB · 可预览
--- 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**: `winget install --id PDFLabs.PDFtk.Server` - **macOS**: `brew install pdftk-java` - **Linux (Debian/Ubuntu)**: `sudo apt-get install pdftk` - **Linux (Red Hat/Fedora)**: `sudo dnf install pdftk` - Access to a terminal or command prompt - Verify installation by running `pdftk --version` ## Step-by-Step Workflows ### Merge Multiple PDFs ```bash pdftk file1.pdf file2.pdf cat output merged.pdf ``` Using handles for more control: ```bash pdftk A=file1.pdf B=file2.pdf cat A B output merged.pdf ``` ### Split a PDF into Individual Pages ```bash pdftk input.pdf burst ``` ### Extract Specific Pages Extract pages 1-5 and 10-15: ```bash pdftk input.pdf cat 1-5 10-15 output extracted.pdf ``` ### Remove Specific Pages Remove page 13: ```bash pdftk input.pdf cat 1-12 14-end output output.pdf ``` ### Rotate Pages Rotate all pages 90 degrees clockwise: ```bash 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): ```bash pdftk input.pdf output secured.pdf owner_pw mypassword user_pw userpass ``` ### Decrypt a PDF Remove encryption using the known password: ```bash 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: ```bash 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): ```bash 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: ```bash pdftk input.pdf stamp overlay.pdf output stamped.pdf ``` ### Extract Metadata Export bookmarks, page metrics, and document information: ```bash pdftk input.pdf dump_data output metadata.txt ``` ### Repair a Corrupted PDF Pass a broken PDF through pdftk to attempt automatic repair: ```bash pdftk broken.pdf output fixed.pdf ``` ### Collate Scanned Pages Interleave separately scanned even and odd pages: ```bash 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](references/pdftk-man-page.md) - Complete manual reference with all operations, options, and syntax - [pdftk-cli-examples.md](references/pdftk-cli-examples.md) - Practical command-line examples for common tasks - [download.md](references/download.md) - Installation and download instructions for all platforms - [pdftk-server-license.md](references/pdftk-server-license.md) - PDFtk Server licensing information - [third-party-materials.md](references/third-party-materials.md) - Third-party library licenses
SKILL.md
元数据
| name | pdftk-server |
|---|---|
| description | 用于使用命令行工具 pdftk (PDFtk Server) 处理 PDF 文件的技能。在需要合并、拆分、旋转、加密、解密、填写表单、添加水印、加盖戳记、提取元数据、将 PDF 拆分为单页、修复损坏的 PDF、附加或提取文件或通过命令行执行任何 PDF 操作时使用。 |
PDFtk Server
PDFtk Server 是一个处理 PDF 文档的命令行工具。它可以合并、拆分、旋转、加密、解密、添加水印、加盖戳记、填写表单、提取元数据,并以多种方式操作 PDF。
使用场景
- 合并多个 PDF 文件为一个
- 将 PDF 拆分为多个单页文件
- 旋转 PDF 页面
- 加密或解密 PDF 文件
- 通过 FDF/XFDF 数据填写 PDF 表单字段
- 应用背景水印或前景戳记
- 提取 PDF 元数据、书签或表单字段信息
- 修复损坏的 PDF 文件
- 附加或提取嵌入 PDF 的文件
- 从 PDF 中移除特定页面
- 整理分开扫描的偶数页和奇数页
- 压缩或解压缩 PDF 页面流
前提条件
- 系统必须安装 PDFtk Server
- Windows:
winget install --id PDFLabs.PDFtk.Server - macOS:
brew install pdftk-java - Linux (Debian/Ubuntu):
sudo apt-get install pdftk - Linux (Red Hat/Fedora):
sudo dnf install pdftk
- Windows:
- 可访问终端或命令提示符
- 通过运行
pdftk --version验证安装
分步工作流程
合并多个 PDF
bash
pdftk file1.pdf file2.pdf cat output merged.pdf使用句柄进行更多控制:
bash
pdftk A=file1.pdf B=file2.pdf cat A B output merged.pdf将 PDF 拆分为单页
bash
pdftk input.pdf burst提取特定页面
提取第 1-5 页和第 10-15 页:
bash
pdftk input.pdf cat 1-5 10-15 output extracted.pdf移除特定页面
移除第 13 页:
bash
pdftk input.pdf cat 1-12 14-end output output.pdf旋转页面
将所有页面顺时针旋转 90 度:
bash
pdftk input.pdf cat 1-endeast output rotated.pdf加密 PDF
设置所有者密码和用户密码,使用 128 位加密(默认):
bash
pdftk input.pdf output secured.pdf owner_pw mypassword user_pw userpass解密 PDF
使用已知密码移除加密:
bash
pdftk secured.pdf input_pw mypassword output unsecured.pdf填写 PDF 表单
从 FDF 文件填充表单字段并压平以防止进一步编辑:
bash
pdftk form.pdf fill_form data.fdf output filled.pdf flatten应用背景水印
在输入的每一页后面放置一个单页 PDF(输入 PDF 应具有透明区域):
bash
pdftk input.pdf background watermark.pdf output watermarked.pdf加盖戳记
在输入的每一页上面放置一个单页 PDF:
bash
pdftk input.pdf stamp overlay.pdf output stamped.pdf提取元数据
导出书签、页面度量和文档信息:
bash
pdftk input.pdf dump_data output metadata.txt修复损坏的 PDF
将损坏的 PDF 通过 pdftk 处理以尝试自动修复:
bash
pdftk broken.pdf output fixed.pdf整理扫描页面
交替排列分开扫描的偶数页和奇数页:
bash
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf故障排除
| 问题 | 解决方法 |
|---|---|
找不到 pdftk 命令 | 验证安装;检查 pdftk 是否在系统 PATH 中 |
| 无法解密 PDF | 确保通过 input_pw 提供正确的所有者或用户密码 |
| 输出文件为空或损坏 | 检查输入文件的完整性;尝试先运行 pdftk input.pdf output repaired.pdf |
| 填写后表单字段不可见 | 使用 flatten 标志将字段合并到页面内容中 |
| 水印未出现 | 确保输入 PDF 有透明区域;对于不透明覆盖,使用 stamp |
| 权限被拒绝错误 | 检查输入和输出路径的文件权限 |
参考
references/ 文件夹中的捆绑参考文档:
- pdftk-man-page.md - 所有操作、选项和语法的完整手册参考
- pdftk-cli-examples.md - 常见任务的实用命令行示例
- download.md - 所有平台的安装和下载说明
- pdftk-server-license.md - PDFtk Server 许可信息
- third-party-materials.md - 第三方库许可