How to convert jpg image file to pdf format on Linux

The JPG (JPEG) format is without any doubt the most popular format used to share images on the Internet. However, there are several advantages in using PDF images compared to JPG images. For one, while JPG is a raster format with lossy compression, PDF is a layout format that contains both vector and raster graphics.

This means that while the printing quality of JPG images depends on their pixel dimensions, PDF image files can print out exactly what you see on screen. Besides, the PDF format supports text search within PDF files using OCR, and can contain richer metadata than JPG format.

If you would like to convert JPG image file to PDF format on Linux, you can use ImageMagic or GhostScript, both of which are free Linux software.

Convert JPG image file to PDF format using ImageMagick

First, install ImageMagick on your system.

For Debian/Ubuntu system:

$ sudo apt-get install imagemagick

For CentOS/RHEL/Fedora system:

$ sudo yum install imagemagick

Among the utilities contained in ImageMagick package, a utility called convert can convert from JPG to PDF. The convert command will scale input image such that it will fit either page width or page height. You can run convert command as follows.

$ convert input.jpg output.pdf

If you want to convert multiple JPG images to one PDF file (with multiple pages):

$ convert input1.jpg input2.jpg input3.jpg output.pdf


$ convert *.jpg output.pdf

Then each JPG file will be converted into one page of the multi-page PDF file.

The convert utility also supports various transformations of input images before PDF conversion, as described in the following.

To specify the dimension of page (i.e., image canvas), you can use "-page" option of convert command. If page dimension is larger than input image size, the image will be placed in lower left corner of a page.

$ convert -page 1600x1200 input.jpg output.pdf

To specify the dimension of image:

$ convert -size 800x600 input.jpg output.pdf

To resize the image:

$ convert -resize 50% input.jpg output.pdf

Convert jpg image file to pdf format using Ghostscript

First, install ghostscript on your system.

For Debian/Ubuntu system:

$ sudo apt-get install ghostscript

For CentOS/RHEL/Fedora system:

$ sudo yum install ghostscript

Then, run gs command to convert a JPG image to PDF format as follows.

$ gs -sDEVICE=pdfwrite -o output.pdf /usr/share/ghostscript/8.71/lib/ -c "(input.jpg) viewJPEG"

To convert multiple JPG images (e.g., input1.jpg, input2.jpg, input3.jpg) to one PDF file (with multiple pages):

$ gs -sDEVICE=pdfwrite -o output.pdf /usr/share/ghostscript/8.71/lib/ -c "(intput1.jpg) viewJPEG showpage (input2.jpg) viewJPEG showpage (intput3.jpg) viewJPEG showpage"

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

3 thoughts on “How to convert jpg image file to pdf format on Linux

  1. Great tips Dan!
    Could you advise in the following problem?
    I have 250 jpg's and want to convert them into 1 pdf (your command works just fine using *.jpg!)
    But a bookmarked indexfile in the beginning of the file using the filename of the pictures
    And if possible I would like 1 page for every picture.

  2. Hi all,
    with Imagemagick, I have found and tested with success this command.
    (with "resize 100%", no image resize is done but a very high Mbyte compression is done!)

    "mogrify -resize 100% -filter Triangle -define filter:support=2 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -interlace none -colorspace sRGB *.jpg"

    When I apply this command on a single image, all works good. But with *.jpg option, the process is working in the system, but after many minutes, no output is generated. Does anyone have an idea or a solution? (I'm using Linux Mint MATE 17.3 64bit)

Leave a Reply to Dan Nanni Cancel reply

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