Like everyone else in the world, I generate my fair share of PDFs. I also have, on occasion, the need to split them up. There are tons of graphical tools that can do this, but I thought it might be fun to find a command line PDF splitter. Thank goodness, as always, I can stand on the shoulders of those who have gone before.
One way to get the job done is to rely on pdftk, a command line tool that is easy enough to install with the standard commands (sudo apt-get install pdftk).
In my example, I have nine page PDF, but I only want pages 8-9 extracted and put into their own PDF file. To accomplish that, I would use the command shown below…items in bold are the filenames, italics the pages I wanted.
pdftk original9pager.pdf cat 8 9 output short_two_pager.pdf
You can also specify a range of pages, as well as extract every page in the PDF, as shown in the commands below.
Note: I’m relying on the commands offered at Linux Commando and I recommend reading that blog entry in its entirety. I merely note the commands here for my own reference.
Additional Commands
$ pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdfpdftk has a few more tricks in its back pocket. For example, you can specify a burst operation to split each page in the input file into a separate output file.$ pdftk myoldfile.pdf burstBy default, the output files are named pg_0001.pdf, pg_0002.pdf, etc.pdftk is also capable of merging multiple pdf files into one pdf.$ pdftk pg_0001.pdf pg_0002.pdf pg_0004.pdf pg_0005.pdf output mynewfile.pdfThat would merge the files corresponding to the first, second, fourth and fifth pages into a single output pdf.
Thanks, Peter Leung from Linux Commando for such easy to follow directions.
Everything posted on Miguel Guhlin’s blogs/wikis are his personal opinion and do not necessarily represent the views of his employer(s) or its clients. Read Full Disclosure
Discover more from Another Think Coming
Subscribe to get the latest posts sent to your email.