How to install PDFTK

PDFTK is a tool that can be used to split and merge PDF files. It is available for both Linux and Windows.

Windows

PDFTK installer for Windows can be downloaded here. After PDFTK is installed, ensure that the directory of pdftk.exe is in the PATH environment variable.

Ubuntu 18.04 and newer

For Ubuntu versions starting from 18.04 and newer versions, use Snap to install PDFTK:

$ sudo snap install pdftk

Ubuntu 16.04 and older

For Ubuntu versions 16.04 and older versions, use Apt to install PDFTK:

$ sudo apt install pdftk

If your installation is successful, you should be able to run pdftk from the shell.

Advertisements

PDFTK: Owner password required error

Problem

You try to manipulate some PDF files using PDFTK and it gives the following error:

Error: Failed to open PDF file:
   101.pdf
   OWNER PASSWORD REQUIRED, but not given (or incorrect)

Solution

The PDF files for which PDFTK prints this error might be password protected or encrypted. If you can open and view the PDF file using any PDF viewer then it might mean that the PDF files are protected or encrypted with an empty password.

To be able to apply PDFTK on these files, you will need to remove the protection or decrypt the files. One way to do this is using the QPDF tool.

Tried with: PDFTK 1.44

How to extract pages from PDF using PDFTK

PDFTK can be used to extract certain pages from one or more PDF files into a new PDF.

To install PDFTK, please follow the instructions here.

Commands like these can be used to extract pages from a PDF file:

# Extract pages 1-3
pdftk in.pdf cat 1-3 output out.pdf

# Extract pages 2, 4 and 6
pdftk in.pdf cat 2 4 6 output out.pdf

# Extract pages 1-3 and 6-10
pdftk in.pdf cat 1-3 6-10 output out.pdf

# Extract pages 1-3 from first and 6-10 from second file
pdftk A=first.pdf B=second.pdf cat A1-3 B6-10 output out.pdf

Tried with: PDFTK 1.44

How to merge PDF files using PDFTK

PDFTK can be used to easily merge or stitch or combine together multiple PDF files into a single PDF file.

To install PDFTK, please follow the instructions here.

To merge PDF files, commands like this can be used:

$ pdftk *.pdf cat output out.pdf

$ pdftk 1.pdf 2.pdf 3.pdf cat output out.pdf

Tried with: PDFTK 1.41

How to split PDF using PDFTK

PDFTK can be used to easily split out pages of a PDF file into separate PDF files at the shell. It is available for both Linux and Windows.

To install PDFTK, please follow the instructions here.

To split a PDF file into multiple PDF files, one per page of the original PDF file, invoke:

$ pdftk foobar.pdf burst output foobar-%d.pdf

If foobar.pdf is a 2 page PDF, this splits it into foobar-1.pdf and foobar-2.pdf.

If you split often, it would be much nicer to invoke the above simply as:

$ splitpdf foobar

To be able to do that on Windows, you can turn the above invocation into a batch file:

REM splitpdf.bat
pdftk %1.pdf burst output %1-%%d.pdf

The %1 is the first input argument to the batch file invocation. And %% is the way to escape %, which is a special character in a batch file.

Reference: Beamer + Ipe + views