How To Join, Split And Password Protect PDF Files From The Linux Command Line

With the Linux command line / Terminal, it is easy to merge, split and edit PDF files. There is a useful tool for that called pdftk which is like the Swiss knife for PDF-related functions.

To install pdftk, open the Linux Terminal and type in

 sudo apt install pdftk

It also has a snap available. This example uses the snap version on Ubuntu.

 sudo snap install pdftk

snap install of pdftk

Merging PDF files:

To merge different PDF files into one using pdftk, the syntax is:

 pdftk file1.pdf file2.pdf cat output newfile.pdf

In this example, different files from 1 to 6, etc are merged into a single output file named doc.pdf. This file has all the pages from the individual source files. So, the command is:

 pdftk 1.pdf 2.pdf 3.pdf 4.pdf 5.pdf 6.pdf cat output doc.pdf

joining pdf files

Another example of merging files:

example of joining pdf files

Besides merging, you can also selectively choose pages to omit or include.

Suppose you want to exclude the 4th page of the source PDF file named doc.pdf, then it can be done as follows:

 pdftk doc.pdf cat 1-3 5-end output doc_no_pg4.pdf

excluding specific pages using pdftk

This output file will have all the pages except the one excluded. Pretty cool.

Encrypting and password-protecting PDFs:

pdftk also can encrypt the source PDFs and set a password to open them. To do that, specify the encryption strength.

So, to add 128-bit encryption to a source PDF named doc.pdf, and set a password hello! to open it, the command will be:

 pdftk doc.pdf output doc_encrypted.128.pdf user_pw hello!

adding encryption and password to pdf files with pdftk

The encryption strength has to be specified after the . and the user_pw parameter for adding a password to open the file.

password for opening the pdf file

Splitting a PDF file into pages:

To split a PDF file named doc.pdf into individual pages, use the burst parameter:

 pdftk doc.pdf burst

split a pdf file using pdftk

This burst function will show the individual pages as different files.

pdf file split into different pages

Besides these basic operations, pdftk can also rotate pages, repair PDFs, and do a lot more.

To list its various functions, type in

 pdftk –help

help screen for pdftk

Also, just using pdftk without any parameters or input files will list its commonly used functions.

 pdftk

common parameter for using pdftk

This tiny utility makes it easy to manage and edit PDF files all through a few simple commands.

All done.

Leave a Comment