It is suggested that you use Python modules or Stirling-PDF instead of
pdftkto manipulating PDFs for several reasons. First, even thoughpdftkis a great command-line tool, it is hard to remember its syntax. On the contratry, Python code is easy to read and understand (even though it is more verbose). Second, it is not easy to havepdftkinstalled and configured on macOS. If you prefer a GUI-based application for manipulating PDF files, Stirling-PDF is is a robust, locally hosted web-based PDF manipulation tool using Docker.Please refer to PyPDF2 Examples for a simple example of extracting PDF pages using the Python package
PyPDF2. If you need to edit PDF pages, please refer to Editing PDF Files for possible tools. If you do have to stick withpdftk, below are concrete examples on how to use it.
Install pdftk on Ubuntu / Debian¶
wajig install pdftk-javaExamples of Using pdftk¶
Fill in forms in an I-9 doc.
:::bash # dump fields in the form (optional, for human examination only) pdftk i9.pdf dump_data_fields > fields.txt # generate a FDF data file pdftk i9.pdf generate_fdf output data.fdf # after fill in fileds in the FDF file, run the following command pdftk i9.pdf fill_form data.fdf output i9_2.pdfIf the PDF form to fill in using
pdftkis encrypted, you have to decrypt it first. SmallPDF is a good online service, which can help you unlock PDF documents if you don’t have the encryption password.Notice that some PDF forms (e.g., time card, I-9 form, etc.) cannot be saved (only a blank copy can be saved). after filled in using Adobe Reader.
pdftkprovides a solution to this problem.Extract pages (from 149 to 186) from the PDF file “training.pdf” as “chap_05.pdf”
:::bash pdftk training.pdf cat 149-186 output chap_05.pdfCombine all my i-20s (all PDF files in current directory) into a single file.
:::bash pdftk *.pdf cat output i-20_all.pdfCombine scaned pages into the right order.
:::bash pdftk A=20141206171918820.pdf B=20141206171951015.pdf cat A1 B1 A2-3 output i-20.pdfRotate the first PDF page to 90 degrees clockwise
:::bash pdftk in.pdf cat 1east 2-end output out.pdfRotate all pages in the second PDF file to 180 degrees
:::bash pdftk A=m11.pdf B=m25.pdf cat A Bsouth output comed.pdfRotate an entire PDF document to 180 degrees
:::bash pdftk in.pdf cat 1-endsouth output out.pdf