Convert a multi-page PDF file into multiple image files

Published on
26,639 Points
6 Endorsements
Last Modified:
Joe Winograd
50+ years in computer industry •Everything from development to sales •CIO •Windows •Document Imaging •EE MVE 2015,2016,2018 •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
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free