How to split PDF files from Linux Terminal with PDFtk

One of the best ways to split PDF files on Linux is not using GUI tools like Evince or Ocular. Instead, use a terminal application called PDFtk . Not only can it split PDF files, it can also edit and modify these files.

Install PDFtk

This application has been released for a while and can be easily installed on most Linux distributions. Open a terminal window and follow the instructions below to install the application.

Note: To install PDFtk, you must use Ubuntu, Debian, Arch Linux, Fedora or OpenSUSE. If you haven't run any Linux distributions yet, follow the instructions at the bottom.

Ubuntu

 sudo apt install pdftk 

Debian

 sudo apt-get install pdftk 

Arch Linux

PDFtk can be used on Arch Linux, but users will not be able to install software from the main sources of Arch Linux. Instead, interacting with Arch Linux AUR is a mandatory condition. To start installing PDFtk on Arch, open a terminal and use the Pacman package manager to synchronize the latest version of the Git tool.

Note: Having another PDFtk package on AUR makes it easier to install the program, because it decodes the program, instead of building from the source code. We do not recommend this option, as there are some problems with the built-in GCC-GCJ package.

 sudo pacman -S git 

Now that Git is working on Arch Linux, you will be able to use it to download the latest version of PDFtk AUR. In the terminal, use git clone to download the build guide file.

 git clone https://aur.archlinux.org/pdftk.git 

Use the CD command, move the terminal from the user's Home folder to the newly cloned pdftk folder.

 cd pdftk 

Inside the PDFtk source folder, start the build process by running makepkg. Remember that running makepkg will automatically download, compile and install any required dependencies. However, if these dependencies are not taken automatically, you will need to install them manually. All dependent files for the PDFtk AUR package can be found here.

Fedora

Currently, there is no PDFtk Fedora package in the software repository. Fortunately, it's easy to make OpenSUSE packages work. Start using wget to download the necessary packages.

 wget http://ftp.gwdg.de/pub/opensuse/distribution/leap/42.3/repo/oss/suse/x86_64/pdftk-2.02-10.1.x86_64.rpm 
wget http://ftp.gwdg.de/pub/opensuse/distribution/leap/42.3/repo/oss/suse/x86_64/libgcj48-4.8.5-24.14.x86_64.rpm

Use the CD command, move the terminal to the Downloads folder.

 cd ~ / Downloads 

Finally, use the DNF package manager to install PDFtk:

 sudo dnf install libgcj48-4.8.5-24.14.x86_64.rpm pdftk-2.02-10.1.x86_64.rpm -y 

OpenSUSE

 sudo zypper install pdftk 

Build from the source code

Building PDFtk from source does not take you too much effort because there are already built-in files built into the source directory. To build the program from the source code, you first need to download the code. To get the code, use the wget download tool in the terminal device.

How to split PDF files from Linux Terminal with PDFtk Picture 1

To make sure PDFtk is built correctly, make sure you have GCC, GCJ and libgcj installed on Linux.

 wget https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-2.02-src.zip 

Next, use the Unzip command to extract the PDFtk Zip folder into the Linux Download folder. If you have not installed the Unzip application, do this to "extract" the zip file and install it.

 cd ~ / Downloads 
unzip pdftk-2.02-src.zip

Extracting PDFtk will create a folder 'pdftk-2.02-src' in Downloads. In the terminal, use the CD command to enter.

 cd pdftk-2.02-src 

In the original PDFtk folder, you cannot manipulate much. To compile anything, we need to move the terminal to the subdirectory of PDFtk.

 cd pdftk 

The PDFtk subdirectory has dozens of dedicated Makefiles that users can use to automatically create different operating systems. Use the LS command, list the contents of the directory.

 ls 

Look over and find the specific Makefile you need and start the build process with the command below. Remember to change the " Makefile.filename " in the command below with the name of the Makefile you need to use.

 make -f Makefile.filename 

Use PDFtk

One of the main attractions of PDFtk is the ability to intervene and split PDF files. For example, to split a PDF file so that each page of the document becomes a separate file, try using the burst command:

How to split PDF files from Linux Terminal with PDFtk Picture 2

 pdftk testfile.pdf burst 

PDFtk will export split files in the same location as the source file.

If you want to merge all PDF files broken down into a single file, start by renaming the original PDF file (to be safe).

 mv testfile.pdf testfile.bak 

Now, the tested PDF file is safe, combining everything with PDFtk. First, use the LS command to view the files in the directory.

 ls 

Next, run the LS command again, but this time use it to store all PDF files.

 ls * .pdf >> pdf-filenames.txt 

Assign the contents of the file pdf-filenames.txt to the Bash variable. The Bash variable in this case is not simply a wildcard when we join the PDF files but also marks the files in order.

 value = $ ( 

Finally, combine PDF files with PDFtk and $ values.

 pdftk $ value cat output recombined-document.pdf 

See more:

  1. How to split PDF file without Vietnamese error
  2. Split or merge PDF files in Linux
  3. How to edit PDF file using FormSwift online
4.3 ★ | 8 Vote

May be interested

  • How to use Linux Terminal as a computerHow to use Linux Terminal as a computer
    join tipsmake.com to learn how to use the terminal in linux as a computer, regardless of which distribution you are running, via the following article!
  • How to fix the problem of being unable to enter Terminal in LinuxHow to fix the problem of being unable to enter Terminal in Linux
    nothing is perfect and sometimes, even terminal can stop responding or ignore what you type. if your terminal crashes and you can't enter it, here are some of the most common causes and solutions for them.
  • Make Terminal More Fun with These 8 Linux Tools!Make Terminal More Fun with These 8 Linux Tools!
    these tools will help you be more efficient, productive, and even have more fun working in terminal. let's take a look at some of our favorite command line tools!
  • How to Find Files in LinuxHow to Find Files in Linux
    if you don't know how, finding files in linux can be quite difficult. here, the best way is to use a few different terminal commands. they are much more powerful than the simple search features on other operating systems, and when you know how to use them well, you will have complete control over your files.
  • 7 Ways to Restart Linux from Terminal7 Ways to Restart Linux from Terminal
    restarting linux from the terminal may seem difficult, but don't worry, it's quite simple once you know the right commands. restarting linux is necessary after updating, troubleshooting, or performing system maintenance.
  • 5 interesting entertainment games in Linux Terminal5 interesting entertainment games in Linux Terminal
    if you are looking to learn how to use the linux terminal, a great approach for beginners is to install and play some simple games.
  • 14 interesting Linux commands in Terminal14 interesting Linux commands in Terminal
    terminal is a very powerful tool, but it can become 'interesting' through a few bash commands that quantrimang will introduce to you later. let's follow up and find out because some commands are quite useful.
  • The fastest and most effective way to split compressed files with WinRARThe fastest and most effective way to split compressed files with WinRAR
    for large files, when sharing on upload sites, to speed up file transfer and download files faster and more stable, many people have chosen to split compressed files using winrar. so how to split files with winrar? please join tipsmake in following the instructions shared in the article below.
  • 6 interesting terminal commands on Mac6 interesting terminal commands on Mac
    terminal is a handy utility, often found on unix-based computers, such as linux and macos. there are many interesting things to do in the terminal. regardless of your experience, you can use these great terminal commands on mac.
  • How to Split PDF FilesHow to Split PDF Files
    many people choose to use pdf files to take advantage of the document's ability to protect its original content. however, this makes splitting pdf files a bit more difficult than other types of formats. with adobe acrobat, you can use the built-in split document feature to split files. but if you don't want to spend money on acrobat, you can still accomplish this goal with many other free alternatives.