The pdftk command provides many options for working with PDFs, including merging pages, encrypting files, applying watermarks, compressing files, and even repairing PDFs -- easily and on the command line. Credit: Toshiyuki IMAI While PDFs are generally regarded as fairly stable files, there’s a lot you can do with them on both Linux and other systems. This includes merging, splitting, rotating, breaking into single pages, encrypting and decrypting, applying watermarks, compressing and uncompressing, and even repairing. The pdftk command does all this and more. The name “pdftk” stands for “PDF tool kit,” and the command is surprisingly easy to use and does a good job of manipulating PDFs. For example, to pull separate files into a single PDF file, you would use a command like this: $ pdftk pg1.pdf pg2.pdf pg3.pdf pg4.pdf pg5.pdf cat output OneDoc.pdf That OneDoc.pdf file will contain all five of the documents shown and the command will run in a matter of seconds. Note that the cat option directs the files to be joined together and the output option specifies the name of the new file. You can also pull select pages from a PDF to create a separate PDF file. For example, if you wanted to create a new PDF with only pages 1, 2, 3, and 5 of the document created above, you could do this: $ pdftk OneDoc.pdf cat 1-3 5 output 4pgs.pdf If, on the other hand, you wanted pages 1, 3, 4, and 5, we might use this syntax instead: $ pdftk OneDoc.pdf cat 1 3-end output 4pgs.pdf You have the option of specifying all individual pages or using page ranges as shown in the examples above. This next command will create a collated document from one that contains the odd pages (1, 3, etc.) and one that contains the even pages (2, 4, etc.): $ pdftk A=odd.pdf B=even.pdf shuffle A B output collated.pdf Notice that the shuffle option make this collation possible and dictates the order in which the documents are used. Note also: While the odd/even pages example might suggest otherwise, you are not restricted to using only two input files. If you want to create an encrypted PDF that can only be opened by a recipient who knows the password, you could use a command like this one: $ pdftk prep.pdf output report.pdf user_pw AsK4n0thingGeTn0thing The options provide for 40 (encrypt_40bit) and 128 (encrypt_128bit) bit encryption. The 128 bit encryption is used by default. You can also break a PDF file into individual pages using the burst option: $ pdftk allpgs.pdf burst $ ls -ltr *.pdf | tail -5 -rw-rw-r-- 1 shs shs 22933 Aug 8 08:18 pg_0001.pdf -rw-rw-r-- 1 shs shs 23773 Aug 8 08:18 pg_0002.pdf -rw-rw-r-- 1 shs shs 23260 Aug 8 08:18 pg_0003.pdf -rw-rw-r-- 1 shs shs 23435 Aug 8 08:18 pg_0004.pdf -rw-rw-r-- 1 shs shs 23136 Aug 8 08:18 pg_0005.pdf The pdftk command makes pulling together, tearing apart, rebuilding and encrypting PDF files surprisingly easy. To learn more about its many options, I check out the examples page from PDF Labs. Related content how-to How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe