<

Go Premium for a chance to win a PS4. Enter to Win

x

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

Published on
15,155 Points
2,055 Views
1 Endorsement
Last Modified:
Joe Winograd, EE MVE 2015&2016
50+ yrs in computer industry. Everything from programming to sales. OS kernel dev on mainframes. CIO. Document imaging. EE MVE 2015 & 2016.
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:

output.jpg
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:

output-3x2.jpg
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:

output-2x10000.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:

output-pretty.jpg
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

input.pdf


 
1
Comment
0 Comments

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month