Convert Images to PDF

Convert Images to PDF with Terminal

Recently I was converting an image to PDF using Preview under OS X and wasn’t pleased when I discovered that it converted the PNG image to PDF but it also rotated it. I began wondering if it was possible to easily convert images to PDF using the Terminal application of OS X or my preferred terminal app, iTerm.

I discovered Image Magick which is a really cool program that provides easy and fast conversion of images to PDF from your Terminal. This is available for OS X, Arch Linux, Ubuntu, CentOS and Red Hat. You install it using your package manager so either Homebrew, Pacman, Apt-get or Yum respectively. I’ve provided the installation instructions for all of these operating systems below:

Homebrew OSX

brew install imagemagick

Arch Linux

pacman -S imagemagick

CentOS / Red Hat (With EPEL and Remi repositories enabled.)
Install Dependencies First

yum install -y gcc php-devel php-pear

Install Image Magick

yum install -y ImageMagick ImageMagick-devel


sudo apt-get install imagemagick

Then once you have Image Magick installed doing conversions is simple. You can either convert one file at a time or you can convert a folder of images into one PDF.

Convert all JPG images in a folder to one PDF File:

convert *.jpg output.pdf

Convert One Image to PDF

image.jpg output.pdf

If the resulting PDF files are too large, consider using the quality parameter:

convert -quality 60 image.jpg output.pdf