How to Convert Image to Pdf in Linux

Sometimes you may need to convert an image to pdf in Linux. For example, you may want to add an “export to pdf” option for your application or website. In this article, we will look at how to convert image to pdf in linux using CLI (command line interface). You can use these steps to convert JPG to PDF, PNG to PDF in Ubuntu as well as other Linux systems such as Debian, Redhat, CentOS.

How to Convert Image to Pdf in Linux

If you are looking for a visual tool to convert images into pdf, you can try an online pdf converter like smallpdf.

Here are the steps to convert image to pdf using CLI. We will need a free library called imagemagick for this purpose.

Also read : How to search in vi editor


1. Update ubuntu

Open terminal and run the following command to update ubuntu libraries.

$ sudo apt-get update

Also read : How to Set Default Text Editor in Ubuntu


2. Install ImageMagick

Run the following command to install ImageMagick. If you see any prompts, enter ‘Y’.

$ sudo apt-get install imagemagick

Also read : How to Undo Git Add Before Commit


3. Convert image to pdf

Once imagemagick is installed, you can convert images to pdf using convert command. Here is the syntax to convert image to pdf

$ sudo convert /path/to/image /path/to/pdf

Let us say you want to convert /home/image.jpg to /home/test.pdf then run the following command

$ sudo convert /home/image.jpg /home/test.pdf

Also read : How to Install AWS CLI in Linux

If you want to convert multiple images into pdf list them one after the other and at the end mention the name of your pdf file.

$ sudo convert image1.jpg image2.png image3.bmp test.pdf

This is a very useful way to add “download as pdf” or “export as pdf” feature to your application or website. You can easily embed this piece of code within your php, python or ruby module and get your application to start exporting images as pdf.

Also read : How to Install git in Ubuntu
How to Install virtualenv in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *