Last updated on October 3, 2020 by Dan Nanni
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.
First, install ImageMagick on your system.
$ sudo apt-get install imagemagick
$ 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
Or:
$ 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
First, install ghostscript
on your system.
$ sudo apt-get install ghostscript
$ 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/viewjpeg.ps -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/viewjpeg.ps -c "(intput1.jpg) viewJPEG showpage (input2.jpg) viewJPEG showpage (intput3.jpg) viewJPEG showpage"
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean