Get the highlights in your inbox every week.
Edit PDFs on the Linux command line | Opensource.com
Edit PDFs on the Linux command line
Use qpdf and poppler-utils to split, modify, and combine PDF files.
Many of the documents you receive come in PDF format. Sometimes those PDFs need to be manipulated. For example, pages might need to be removed or added, or you might need to sign or change a specific page.
Whether good or bad, this is the reality we all live in.
There are some fancy graphical user interface tools that let you edit PDFs, but I have always been most comfortable with the command line. Of the many command-line tools for this task, the ones I use when I want to modify a PDF are
On Linux, you can install
poppler-utils using your package manager (such as
dnf.) For example, on Fedora:
$ sudo dnf install qpdf poppler-utils
qpdf command can do a lot, but I mostly use it for:
- Splitting a PDF into separate pages
- Concatenating, or combining, PDFs into one file
To split a PDF into separate pages:
qpdf --split-pages original.pdf split.pdf
This generates files like
split-02.pdf, and so on. Each file is a single-page PDF file.
Concatenating files is a little subtler:
qpdf --empty concatenated.pdf --pages split-*.pdf --
This is what
qpdf does by default. The
--empty option tells qpdf to start with an empty file. The two dashes (
--) at the end signals that there are no more files to process. This is a case where the parameters reflect an internal model, rather than what people use it for, but at least it runs and produces valid PDFs!
This package contains several utilities, but the one I use the most is pdftoppm, which converts PDF files to portable pixmap (
ppm) image files. I usually use it after I split pages with
qpdf and need to convert a specific page to an image that I can modify. The
ppm format is not well known, but the important thing about it is that most image manipulation methods, including ImageMagick, Pillow, and many other options, work with it. Most of these tools can save files back to PDF, too.
My usual workflow is:
qpdfto split the PDF into pages.
poppler-utilsto convert the pages that need to be changed into images.
- Modify the images as needed and save them to PDF.
qpdfto concatenate the pages back into one PDF.
There are many great open source commands to deal with PDFs, whether you're shrinking them, creating them from text files, converting documents, or trying your best to avoid them altogether. What are your favorite open source PDF utilities? Please share them in the comments.