How to edit a PDF file on Linux

Last updated on July 29, 2020 by Dan Nanni

pdftk (PDF Toolkit) is a command-line tool which enables you to edit PDF files. pdftk is freely available on Linux, MS Windows, MacOS X and FreeBSD. Using pdftk, you can edit PDF files without having to pay for a commercial PDF editor. If you would like to install pdftk on Linux, proceed as follows.

Install pdftk on Linux

For Ubuntu or Debian:

To install pdftk on Ubuntu or Debian, simply use apt-get:

$ sudo apt-get install pdftk

For CentOS, Fedora or RHEL:

To install pdftk on CentOS, Fedora or RHEL, you can build it from the source as follows.

$ sudo yum -y install gcc gcc-java
$ wget http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-1.44-src.zip
$ unzip pdftk-1.44-src.zip
$ cd pdftk-1.44-dist/pdftk
$ make -f Makefile.Redhat
$ sudo make install

For Other OS Platforms:

To install pdftk on other platforms such as MS Windows and MacOS X, you can download ported versions of pdftk ports for Windows and MacOS.

Edit PDF Files with pdftk

Once you have installed pdftk on your system, you can edit PDF files using pdftk as follows.

1. Merge several PDF files into one PDF file

$ pdftk input1.pdf input2.pdf input3.pdf cat output final.pdf 

2. Extract pages from a PDF file

For example, the following command extracts pages 3, 4, 5 and makes them into a new PDF file.

$ pdftk input.pdf cat 3-5 output final.pdf

3. Remove pages from a PDF file

For example, the command below removes page 3 and creates a new PDF without the page.

$ pdftk input.pdf cat 1-2 4-end output final.pdf

4. Rotate each page of a multi-page PDF document 180 degrees

$ pdftk input.pdf cat 1-endsouth output final.pdf

5. Rotate each page of a multi-page PDF document 90 degrees clockwise

$ pdftk input.pdf cat 1-endeast output final.pdf

6. Rotate each page of a multi-page PDF document 90 degrees counterclockwise

$ pdftk input.pdf cat 1-endwest output final.pdf

7. Reverse the order of pages in a multi-page PDF document

$ pdftk input.pdf cat end-1 output final.pdf

8. Select pages of different PDF documents into a new PDF file

The command below extracts pages 3, 4, 5 from input1.pdf, extracts pages 1, 2, 3 from input2.pdf, extracts page 10 from input1.pdf, and converts these into a new PDF file called final.pdf.

$ pdftk A=input1.pdf B=input2.pdf cat A3-5 B1-3 A10 output final.pdf

9. Add a watermark to a PDF file

The command below applies a watermark image file (watermark.pdf) to every page of input.pdf.

$ pdftk input.pdf background watermark.pdf output final.pdf

10. Merge two PDF files as odd and even pages

$ pdftk A=odd.pdf B=even.pdf shuffle A B output final.pdf

11. Merge two PDF files as odd and reversed even pages

$ pdftk A=odd.pdf B=even.pdf shuffle A Bend-1 output final.pdf

12. Merge two PDF files as odd and reversed/180-rotated even pages

$ pdftk A=odd.pdf B=even.pdf shuffle A Bend-1S output final.pdf 

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean