Editing PDF with Linux terminal

Editing PDF with Linux terminal

Problem

During my document management on Linux, most of the time the easiest way is to split PDF documents into pages and then merge them with one signed, scanned page.

In this blog post, I will show how to do this with the Linux terminal.

Solution

We will need pdftoppm which is part of the poppler-utils package.

If your distribution doesn't come with it preinstalled, you can get it with the command:

sudo apt-get install poppler-utils

To split the PDF document into images per page run:

pdftoppm input.pdf out -png

For merging them back we can use the convert command-line tool:

convert out1.png out2.png signed.png document.pdf

convert comes with ImageMagick package:

sudo apt-get install imagemagick

Depending on your Linux distribution and package versions you may get a permission error stating:

convert-im6.q16: not authorized `filename.pdf' @ error/constitute.c/WriteImage/1037.

This is caused by a policy that defends against Ghostscript vulnerability. The vulnerability is currently fixed but the appropriate policy is still in place. The simplest fix is to run:

sudo mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xmlout

That's all for now. Time by time I will update this manual with new tricks and tips for PDF manipulation.


Link
No links yet.