pdftk Command: Tutorial & Examples
Manipulate PDF files
pdftk
(PDF Toolkit) is a command-line utility for manipulating PDF files. It allows you to perform various tasks such as merging, splitting, rotating, and modifying PDF
documents.
To use pdftk
, you need to have the utility installed on your system. Here is an overview of some common tasks you can perform with pdftk
:
Merge multiple PDF files into a single document:
pdftk file1.pdf file2.pdf cat output merged.pdf
This merges the contents of "file1.pdf"
and "file2.pdf"
into a new PDF file called "merged.pdf"
.
Combine even and odd pages into one document
pdftk A=even.pdf B=odd.pdf shuffle A B output combined.pdf
Split a PDF file into multiple documents:
pdftk input.pdf cat 1 output page1.pdf
pdftk input.pdf cat 2-end output pages2-end.pdf
This splits "input.pdf"
into two separate PDF files: "page1.pdf"
contains the first page, and "pages2-end.pdf"
contains the remaining pages.
Rotate the pages of a PDF file:
pdftk input.pdf cat 1east 2east 3-endwest output output.pdf
This rotates the first and second pages of "input.pdf"
90 degrees clockwise and the remaining pages 90 degrees counterclockwise, and saves the result in "output.pdf"
.
Rotate all pages by 180 degrees
pdftk inputfile.pdf cat 1-endS output outputfile.pdf
Fill out a PDF form:
pdftk form.pdf fill_form data.fdf output filled.pdf
This fills out the form fields in "form.pdf"
using the data in the "data.fdf"
file and saves the result in "filled.pdf"
.
pdftk
has many other options and features that allow you to manipulate PDF files in various ways. You can use the pdftk --help
command to view the available options and
the man pdftk
command to view the manual pages.