November 2, 2024

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.

By admin

Related Post

6 thoughts on “How To Join, Split And Password Protect PDF Files From The Linux Command Line”
  1. It’s actually a nice and helpful piece of info.

    I’m happy that you just shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.

  2. Way cool! Some extremely valid points! I appreciate you penning this post
    and also the rest of the site is also really good.

  3. Please let me know if you’re looking for a article writer
    for your site. You have some really great posts and I believe
    I would be a good asset. If you ever want to take some of the load
    off, I’d really like to write some articles for your blog in exchange for a link
    back to mine. Please blast me an email if interested.
    Thanks!

  4. Everything is very open with a clear description of the challenges.
    It was truly informative. Your site is extremely helpful.
    Thank you for sharing!

  5. Hey I know this is off topic but I was wondering if you knew of any
    widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading
    your blog and I look forward to your new updates.

Comments are closed.