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


Convert a multi-page PDF file into multiple image files

Published on
20,708 Points
6 Endorsements
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.
This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly simple — a single line of code!
In three previous articles here at Experts Exchange, I discussed the excellent (free!) GraphicsMagick package. The first article, Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method, explains how to download and install GraphicsMagick, which is required for the solution presented in this new, fourth article utilizing GraphicsMagick. So if you don't already have GraphicsMagick installed, please read that article.

The second article in the series, Create a PDF file with Contact Sheets (montage of thumbnails) for all JPG files in a folder and each of its subfolders using an automated, batch method, provides a solution to the question of creating a multi-page PDF file from many JPG files, while the third article, Create an image (BMP, GIF, JPG, PNG, TIF, etc.) from a multi-page PDF, provides a solution for creating a JPG file from a multi-page PDF file. This new article addresses a similar, yet different, requirement from a recent question here at EE, namely, conversion of a multi-page PDF into multiple image files — one image file for each page of the PDF.

As with the other solutions, this one is amazingly simple — a single command line call to GraphicsMagick! Here's an example of what the solution looks like:
gm.exe convert input.pdf +adjoin output%02d.jpg

Open in new window

The key to the solution is the +adjoin option, with the "+" being crucial. This tells GraphicsMagick to convert the input file into multiple, numbered output files. Because of this, the output file name must include a printf style formatting specification for the numeric part of the output file name (it may have any string for the leading part of the file name). There are many options in specifying the printf formats, and a complete explanation of printf is beyond the scope of this article. However, for the sake of completeness, let's take a look at the options used in the line of code above:


The "%" is always the beginning character of a printf format. The "d" means that the generated value is a decimal integer and the "02" means that it should be two digits in length, padded with a "0" on the left when necessary. With this explanation, the printf format used in the code sample above will result in these files:


Likewise, if the line of code above ended in...


...the resulting files would be:


If you'd like to learn more about printf, a web search will provide much to study.

Here's another example, shown by a screenshot of the results in a Command Prompt window before and after running the gm.exe command on the six-page PDF file attached to my previous GraphicsMagick article:

The screenshot shows that there was a single PDF file in the folder before issuing the command (input.pdf) and six JPG files after it ran.

There are many more options in the convert sub-command, such as those mentioned in my other three articles, as well as in the documentation at the GraphicsMagick website. If you need more control over the output images, I recommend experimenting with the numerous options.

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

Expert Comment

by:Methew Andrew
Informative article
LVL 62

Author Comment

by:Joe Winograd, Fellow&MVE
Thanks for the compliment — I appreciate it. Regards, Joe

Expert Comment

by:Miguel Monteiro
Enlighten me please, although free, what's the use of an external solution for doing something which is already part of the original software - Acrobat ? "Export / (choose which type)" or "Save as/Save as type (choose which)"?
LVL 62

Author Comment

by:Joe Winograd, Fellow&MVE
Hi Miguel,

> although free

A crucial factor for some folks. Acrobat is expensive software — not everyone can afford it. You'll notice in the original question here at EE that inspired this article, the asker said, "If anyone has another free option, let me know."

> what's the use of an external solution doing something which is already part of the original software - Acrobat

Acrobat is also "external" in the sense that it is not part of Windows. For many users, Acrobat is not part of their "original software".

> "Export / (choose which type)" or "Save as/Save as type (choose which)"?

For one file (or a small number of files), this is fine. But many users have hundreds, even thousands, of files on which to operate. In that case, the manual Export or Save As is not the ticket. If you have Acrobat, the Action Wizard will work in some cases, but sometimes the better solution, imo, is a command line tool like gm.exe that can be called from a batch file, program, or script. I have written many programs that call gm.exe to operate on all files in a folder and, often, to recurse into subfolders to an unlimited depth, processing all files along the way. Also, you have a lot more control over the output files, with a fantastic set of options. Acrobat is a fine product (I have both Standard and Professional), but in many situations, I prefer writing a program that calls GraphicsMagick, as well as other software that supports a command line interface, such as Nuance's Power PDF — my EE article, Batch Conversion of PDF, TIFF, and Other Image Formats via Command Line Interface to PDF, PDF Searchable, and TIFF, discusses a good example of that. Regards, Joe

Expert Comment

by:Klllmmm klllmmm

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

In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month