Software, Technology

How-to: Convert JPG to PDF using ImageMagick

It’s a common enough task, trying to convert multiple jpg files into one pdf, particularly when I don’t need these to be converted with such high quality, I just want the black and white text readable.

I can scan, crop, and monochrome in a graphics program but compiling them into a single PDF booklet was always tricky. Which is how I started using ImageMagick.

ImageMagick is a command line conversion program that is capable of so many more batch operations than this – resizing, compression, format conversion – and it’s available on all platforms – Linux, Windows and Mac.

Bear in mind that creating a PDF document from multiple JPEG images can take some time and you may want to trial different settings for size and quality of output, so I suggest you make a copy of the JPEG files in a temporary folder to play around with and use Imagemagick on those, NOT your originals. Reducing the resolution as a first step will also make things much quicker.

Originally I was just using the basics:

convert *.jpg output.pdf and/or convert *.jpg -adjoin output.pdf

which works most of the time, however there’s a bug in the convert routine which can in some versions give a segmentation fault when converting a number of JPEG files to one PDF file.

What this command does is take all the .jpg’s (or format of your choice) in a folder and convert them to a single PDF – you can name it whatever you like.

You can avoid the segmentation fault bug and do the compression at the same time if you use

convert *.JPG -compress Zip output.pdf

but the zip compression appears quite inefficient and results in huge file sizes.

You could resize and lower the quality of the images using;

mogrify -resize 50% -quality 25

Which overwrites the originals. You can combine resizing and conversion using

convert -quality 25 -resize 50% *.jpg -adjoin output.pdf

which works, but takes longer as you’re combining batch operations.

And yes, you can resizing images without overwriting the originals by specifying a new file name;

convert ‘*.JPG’ -resize 640×480 newfile%03d.jpg

which outputs the converted images as newfile001.jpg, newfile002.jpg, and so on. Alternatively, if you want to retain the original file name and prepend new, you could use a bit more code:

for file in *.JPG ; do convert “$file” -resize 640×480  “new-${file}” ; done

This is just a sample of what Imagemagick can do if you are prepared to experiment at the command line. RC

Related: How-to: Clean Up Video Soundtrack using ffmpeg, Audacity and Openshot

About Robin Catling

Robin Catling gained degrees in both arts and technology which led to a diverse portfolio of employment. A freelance systems analyst, project manager and business change manager for the likes of American Express, British Airways and IBM, he moved on to web design, journalism and technical authoring. He has also worked in film and television, both behind and in front of the camera, including productions by Steven Spielberg, Martin Scorcese, Ron Howard and Ridley Scott. A qualified three-weapon coach, he runs West Devon Swords teaching sports fencing to all age groups, and in recent years qualified with the British Federation of Historical Swordplay to teach medieval and renaissance combat in the Historical Western Martial Arts.


4 thoughts on “How-to: Convert JPG to PDF using ImageMagick

  1. I was reading through some of your posts on this website and I believe this site is very informative! Keep on posting.

    Posted by edouard256 | Dec 19, 2013, 7:04 pm


  1. Pingback: Av8 - Dec 15, 2013

  2. Pingback: How-to: Animated GIFs using GIMP | Everything Express - Mar 16, 2014

  3. Pingback: How-to: the Need for Digital Asset Management | Everything Express - May 4, 2014

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Twitter Updates

Follow us on Twitter @EverythingExpre

Find Us on Facebook

Enter your email address to follow this blog and receive notifications of new posts by email.



BBC World News

BBC World News
Opens the BBC World News page.
%d bloggers like this: