How to convert jpg image file to pdf format on Linux

The jpg 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, 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

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 jpg image to pdf format as follows.

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

To convert multiple jpg images to one pdf file (with multiple pages):

$ gs -sDEVICE=pdfwrite -o output.pdf /usr/share/ghostscript/8.71/lib/viewjpeg.ps -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.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. 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.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

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

Current ye@r *