pdftk-server

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDFtk Server

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.
PDFtk Server是一款用于处理PDF文档的命令行工具。它可以合并、拆分、旋转、加密、解密、添加水印、加盖图章、填充表单、提取元数据,并以多种方式操作PDF。

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
  • 将多个PDF文件合并为一个
  • 将PDF拆分为单独的页面
  • 旋转PDF页面
  • 加密或解密PDF文件
  • 从FDF/XFDF数据填充PDF表单字段
  • 添加背景水印或前景图章
  • 提取PDF元数据、书签或表单字段信息
  • 修复损坏的PDF文件
  • 附加或提取PDF中嵌入的文件
  • 从PDF中删除特定页面
  • 整理分开扫描的奇偶页
  • 压缩或解压缩PDF页面流

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
  • 系统上必须安装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
  • 可访问终端或命令提示符
  • 通过运行
    pdftk --version
    验证安装

Step-by-Step Workflows

分步操作流程

Merge Multiple PDFs

合并多个PDF

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
bash
pdftk file1.pdf file2.pdf cat output merged.pdf
使用句柄实现更精准的控制:
bash
pdftk A=file1.pdf B=file2.pdf cat A B output merged.pdf

Split a PDF into Individual Pages

将PDF拆分为单独页面

bash
pdftk input.pdf burst
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
提取第1-5页和第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
删除第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
将所有页面顺时针旋转90度:
bash
pdftk input.pdf cat 1-endeast output rotated.pdf

Encrypt a PDF

加密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
设置所有者密码和用户密码,采用128位加密(默认):
bash
pdftk input.pdf output secured.pdf owner_pw mypassword user_pw userpass

Decrypt a PDF

解密PDF

Remove encryption using the known password:
bash
pdftk secured.pdf input_pw mypassword output unsecured.pdf
使用已知密码移除加密:
bash
pdftk secured.pdf input_pw mypassword output unsecured.pdf

Fill a PDF Form

填充PDF表单

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
从FDF文件填充表单字段,并使用扁平化处理防止后续编辑:
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
将单页PDF作为背景放置在输入PDF的每一页之后(输入PDF需包含透明区域):
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
将单页PDF作为前景覆盖在输入PDF的每一页之上:
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
导出书签、页面指标和文档信息:
bash
pdftk input.pdf dump_data output metadata.txt

Repair a Corrupted PDF

修复损坏的PDF

Pass a broken PDF through pdftk to attempt automatic repair:
bash
pdftk broken.pdf output fixed.pdf
将损坏的PDF通过pdftk处理,尝试自动修复:
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
交错合并分开扫描的偶数页和奇数页:
bash
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf

Troubleshooting

故障排除

IssueSolution
pdftk
command not found
Verify installation; check that pdftk is in your system PATH
Cannot decrypt PDFEnsure you are providing the correct owner or user password via
input_pw
Output file is empty or corruptCheck input file integrity; try running
pdftk input.pdf output repaired.pdf
first
Form fields not visible after fillUse the
flatten
flag to merge fields into the page content
Watermark not appearingEnsure the input PDF has transparent regions; use
stamp
for opaque overlays
Permission denied errorsCheck file permissions on input and output paths
问题解决方案
pdftk
命令未找到
验证安装情况;检查pdftk是否在系统PATH中
无法解密PDF确保通过
input_pw
参数提供了正确的所有者或用户密码
输出文件为空或损坏检查输入文件的完整性;先尝试运行
pdftk input.pdf output repaired.pdf
修复
填充后表单字段不可见使用
flatten
参数将字段合并到页面内容中
水印未显示确保输入PDF包含透明区域;对于不透明覆盖层,使用
stamp
命令
权限被拒绝错误检查输入和输出路径的文件权限

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
references/
文件夹中包含的参考文档:
  • pdftk-man-page.md - 包含所有操作、选项和语法的完整手册参考
  • pdftk-cli-examples.md - 常见任务的实用命令行示例
  • download.md - 全平台的安装和下载说明
  • pdftk-server-license.md - PDFtk Server许可信息
  • third-party-materials.md - 第三方库许可信息