How to Convert Image to PDF on Linux Command Line

Often, you may need to convert or add the images to the PDF files, especially if you have an application and you want the users to download the images as PDF files.

There are different online tools that convert the images to PDF. But security is always a concern, and you can’t trust these online sites with your data. The best method is to convert the images on your machine. Linux offers various command-line utilities to aid you with that. The two common tools are Img2PDF and ImageMagick.

1. ImageMagick

ImageMagick stands out for the image conversion to PDF for its fast speed. The open-source Linux tool utilizes the multiple CPU threads to keep the conversion process fast. Whether converting one image or multiple images, ImageMagick gets the job done.

Let’s first install ImageMagick using the following command:

$ sudo apt update
$ sudo apt install -y imagemagick

For Fedora users, the command is as follows:

$ sudo dnf install imagemagick

With the ImageMagick already installed, navigate to the directory containing your pictures.

The syntax for conversion is as following:

$ convert image demo.pdf

To convert all the images in the current directory to PDF, you can add their names one by one or select the image format if they are the same. In our case, the image formats are in “.jpg”. In this case, our command is as follows:

$ convert *.jpg all.pdf

That’s it! You now have all your images converted into one PDF.

ImageMagick is a great tool for converting the images to PDF on the command line. The only bad side of it is that the resolution for the images changes and the PDF file doesn’t have the full resolution, reducing the image quality.

2. Img2PDF

The ImageMagick converts the images to PDF, but the quality of the images reduces. The alternative is to use the Img2PDF to convert the same photos without losing the image quality. Besides, Img2PDF allows the specification of the image size when converting.

Start by installing Img2PDF using the following command:

$ sudo apt install img2pdf

Img2PDF can also be installed using pip in other distributions:

$ pip install img2pdf

With the tool installed, let’s proceed to convert our images. We use the same pictures as we did with ImageMagick. First, navigate to the directory that contains your images. To convert a single file, use the following syntax:

$ img2pdf img -o converted.pdf

We now have a PDF version of the image. If you want to convert multiple images, you can list them all. Or if they have the same format, use the * shorthand like this :

$ img2pdf *.jpg -o converted.pdf

Conclusion

Converting the images of different formats to PDF shouldn’t trouble you when using Linux. There are command-line utilities at your disposal, and the syntax is easy. This guide has presented two utilities, Img2PDF and ImageMagick, that you can use to convert either one or multiple images to PDF.

Leave a Comment