[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Create an image (BMP, GIF, JPG, PNG, TIF, etc.) from a multi-page PDF

Published on
22,940 Points
1 Endorsement
Last Modified:
Joe Winograd, Fellow&MVE
50+ years in computer industry. Everything from development to sales. CIO. Document imaging. EE MVE 2015, EE MVE 2016, EE FELLOW 2017.
In a previous article here at Experts Exchange, I presented a solution to the question of creating a multi-page PDF file containing contact sheets (aka a montage of thumbnails) for all JPG files in a folder. A recent question here at EE asked for a solution, in essence, to the reverse problem, that is, creating a JPG (or PNG) from a multi-page PDF file. In this case, the solution requires all pages of the PDF to be incorporated into a single image. At the question, I posted a relatively brief solution that uses the same GraphicsMagick software and approach as discussed in the article referred to above. Then I decided to write this new article with a more comprehensive explanation of the solution, including some interesting options.

The method presented here also requires the GraphicsMagick software. Another EE article explains how to download and install it. With GraphicsMagick installed, we're ready to proceed with the solution, which is amazingly simple — one line of code in a command prompt! Here it is:
gm.exe montage input.pdf output.jpg

Open in new window

Below is the resulting JPG from the command above using the six-page input.pdf file attached to this article:

As you can see, the default is to place the multiple pages of the PDF horizontally in the output image. If you prefer a different placement, use the -tile option, which is in the format of columns-by-rows. For example, here's the command to place them 3x2:
gm.exe montage -tile 3x2 input.pdf output.jpg

Open in new window

Below is the resulting JPG from the command above:

If you don't know how many pages are in the PDF, decide on the number of columns you want and make the number of rows very large in order to assure that a single image is created, that is, make sure the number of tiles specified by the -tile parameter is at least as large as the number of input images. For example, you could use 10,000 as the number of rows with 2 as the number of columns, as follows:
gm.exe montage -tile 2x10000 input.pdf output.jpg

Open in new window

With the sample PDF we've been using, the above command creates this JPG:

It is possible to have the output be many other file types, such as:
gm.exe montage input.pdf output.bmp
gm.exe montage input.pdf output.gif
gm.exe montage input.pdf output.png
gm.exe montage input.pdf output.tif

Open in new window

That is, simply specify the appropriate file extension on the name of the output file for the file format that you want. I don't know if all the GraphicsMagick supported formats will work in this particular case, but I have tested BMP, GIF, JPG, PNG, and TIF, all of which work perfectly.

You may, of course, use other options on the GraphicsMagick command line. For example, here's a call that creates a nicer looking version of the image by specifying the -frame option (surrounds each tile with an ornamental border), the -mattecolor option (the color of the frame), and the -shadow option (puts a shadow effect on each tile):
gm.exe montage -tile 2x10000 -frame 12x10 -mattecolor gray -shadow input.pdf output.jpg

Open in new window

With the sample PDF, the above command creates this image:

There are many more options in the montage sub-command — I recommend experimenting with them.

If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe



Featured Post

Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

Join & Write a Comment

This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month