Software & AppsOperating SystemLinux

How To Install and Use pdftk in Ubuntu 18.04 and Later

Ubuntu 11

In this article, we will provide a detailed guide on how to install and use pdftk in Ubuntu 18.04 and later versions. pdftk is a versatile command-line tool for manipulating PDF documents. It has the ability to merge, split, encrypt, decrypt, compress, decompress, and repair PDF files.

Quick Answer

To install and use pdftk in Ubuntu 18.04 and later versions, you have several options. You can install pdftk-java using the apt package handler, build pdftk from source, or install it as a snap package. Once installed, you can use pdftk to merge, split, encrypt, decrypt, compress, decompress, and repair PDF files.

Installation Methods

There are several ways to install pdftk on Ubuntu 18.04 and later versions.

Installing from a Future Ubuntu Release

Starting with Ubuntu 18.10 (Cosmic), pdftk-java is available as a replacement for pdftk. It is recommended for users of Ubuntu 18.10 and later. If you are using an earlier release, you can manually download and install it from the package repository.

To install pdftk-java, run the following command:

sudo apt install pdftk-java

This command uses the apt package handler to install the pdftk-java package.

Installing from Source

If you prefer building pdftk from source, follow these steps:

  1. Install the build tools and dependencies: Run the following command to install the necessary build tools and dependencies:
    sudo apt install git default-jdk-headless ant libcommons-lang3-java libbcprov-java
  2. Download the pdftk fork from Marc Vinyal’s GitLab repository: Use the git clone command to download the repository and cd to change to the directory:
    git clone https://gitlab.com/pdftk-java/pdftk.git
    cd pdftk
  3. Create symbolic links to the required libraries: Run the following commands to create symbolic links:
    mkdir lib
    ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar
  4. Build the JAR package: Use the ant jar command to build the JAR package:
    ant jar
  5. Run the JAR package: Finally, run the JAR package with the following command:
    java -jar build/jar/pdftk.jar --help

Using the pdftk Snap Package

You can install pdftk as a snap package by running the following command:

sudo snap install pdftk

Note that this method may have some limitations and may not work for all use cases.

Using pdftk

Once you have pdftk installed, you can use it to manipulate PDF files. Here are a few examples:

  • Merge two PDF files:
    pdftk file1.pdf file2.pdf cat output merged_file.pdf
    This command concatenates (cat) file1.pdf and file2.pdf and outputs the result to merged_file.pdf.
  • Split a PDF file into individual pages:
    pdftk large_file.pdf burst
    This command splits large_file.pdf into individual pages, each saved as a separate PDF file.
  • Encrypt a PDF file:
    pdftk input.pdf output encrypted.pdf user_pw YOURPASSWORD
    This command encrypts input.pdf with the password YOURPASSWORD and saves the result as encrypted.pdf.

For more information on how to use pdftk, you can check the official documentation here.

Conclusion

In this article, we have provided a detailed guide on how to install and use pdftk in Ubuntu 18.04 and later versions. We hope this guide will be helpful for you in managing and manipulating your PDF files.

Can I install pdftk on Ubuntu versions earlier than 18.04?

Yes, you can manually download and install pdftk from the package repository on Ubuntu versions earlier than 18.04.

What are some common use cases for pdftk?

Some common use cases for pdftk include merging multiple PDF files, splitting a PDF file into individual pages, encrypting and decrypting PDF files, compressing and decompressing PDF files, and repairing corrupted PDF files.

Can I install pdftk using the snap package on all Ubuntu versions?

The snap package method of installing pdftk may have some limitations and may not work for all use cases. It is recommended to check the specific requirements and compatibility before using the snap package.

How can I encrypt a PDF file using pdftk?

To encrypt a PDF file using pdftk, you can use the following command: pdftk input.pdf output encrypted.pdf user_pw YOURPASSWORD. Replace input.pdf with the name of the PDF file you want to encrypt and YOURPASSWORD with your desired password.

Where can I find more information on using pdftk?

You can find more information on using pdftk in the official documentation here. The documentation provides detailed explanations and examples of various pdftk commands and functionalities.

Leave a Comment

Your email address will not be published. Required fields are marked *