Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

How to convert JPG images to PDF using the terminal

Hello, friends. The terminal is a great Linux tool. With it, we can do many things and if we install other programs we can extend its functionality even more. Want an example? Today, you will learn how to convert JPG images to PDF using the terminal.

ImageMagick to the rescue

According to the GitHub profile:

ImageMagick uses multiple threads to increase performance and can read, process or write mega, giga or tera-pixel sized images. The current version is the
ImageMagick 7.1.0 series. It runs on Linux, Windows, Mac OS X, iOS, Android OS and others.

ImageMagick is free software that is delivered as a ready-to-run binary distribution or as source code that you can use, copy, modify and distribute in both open and proprietary applications. It is distributed under an Apache 2.0 derivative license.

In short, ImageMagick is a software tool that you can use for image processing on your computer. Thanks to it, we can do many things with images. That is to say, edit them, manipulate them and so on.

Thanks to ImageMagick, we can convert JPG images to PDF so that we can quickly have them in a document.

- Advertisement -

Let’s get started.

Install ImageMagick on Linux

Fortunately, we can install ImageMagick on many Linux distributions because it is available from the official repositories of many of them.

Regarding Debian, Ubuntu, Linux Mint, Elementary OS and all members of this family, you can open a terminal and run the following command

sudo apt update
sudo apt install imagemagick

Concerning Arch Linux, Manjaro, and derivatives

- Advertisement -
sudo pacman -S imagemagick

Then, we can continue.

How to convert JPG images to PDF using the terminal

The procedure is simple, just follow the following syntax

convert [jpg-file] [output-pdf]

For example,

convert 1.jpg o.pdf
1.- Convert JPG images to PDF
1.- Convert JPG images to PDF

You will get a PDF with the content of the image.

You can add several files at once

convert 1.jpg 2.jpg 3.jpg o.pdf

Remember that I’m working with relative paths, but you can also do it with absolute paths

convert /home/angelo/1.jpg o.pdf

And so on. You can add all the images in a folder.

convert *.jpg o.pdf

By default, ImageMagick uses the highest possible quality to convert images to PDF. But if there are many images, this can cause a problem. So, you can also specify the quality at which you want the images to be converted.

To achieve this, use the --quality option and assign a number less than 100 which is the limit. For example:

convert --quality 75 1.jpg o.pdf

This is especially useful when you have many images or just want a backup.

Possible problem with ImageMagick

It is possible that when you execute the above commands, you get an error like this

convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/421.

This is due to a security issue with Ghostscript. An alternative then is to disable the lock for PDF files.

Edit the configuration file

sudo nano /etc/ImageMagick-6/policy.xml

And edit the line

<policy domain="coder" rights="none" pattern="PDF" />

To this:

<!-- <policy domain="coder" rights="none" pattern="PDF" /> --> -->

So, all we are doing is adding a comment to ignore it.

Save the changes and close the editor. That’s enough.

Conclusion

Doing things through the terminal is not difficult, but it gives us another way of doing things. They are also very useful in scripting and so on.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook