Section:

Examples of converting PDF to image using command-line

Apryse's PDF2Image is a command-line application designed to convert a selected PDF document file to one or more BMP, PNG8, JPEG, PNG, TIFF or RAW image files, while presenting several options to control Resolution, Color Bit Depth and other settings, depending on the output format selected. This section covers the basic use of PDF2Image explaining all the available options.

Basic Syntax

The basic command-line syntax is:

pdf2image [options] file1 file2 folder1 file3 ...

See more options in Command-Line Summary for PDF2Image

Command-Line Summary

The following command-line arguments are available for PDF2Image.

General Usage Examples

Example 1. The simplest command line: Convert PDF to PNG.

Notes:

  • This command line heavily relies on PDF2Image defaults. The default output image format is PNG and all images will be rendered at 92 Dots Per Inch (DPI).
  • The '--o' (or --output) parameter is used to specify the output folder. If this option was not specified, all images would be stored in the current working folder.

pdf2image -o ex1 test/tiger.pdf

Example 2. Convert PDF to JPEG at 300 DPI and higher compression.

Notes:

  • The '-d' (or --dpi) parameter is used to specify the output image resolution.
  • The '-f' (or --format) parameter specifies that the output format is JPEG.
  • The '--verb' option instructs pdf2image to output more feedback in the console window.

pdf2image --output ex2 -d 300 -f jpg --verb 3 --quality 60 test/tiger.pdf

Example 3. Convert a password protected file to a TIFF file of given pixel dimensions.

Notes:

  • In this example, the '--hres' and '--vres' parameters are used instead of the '--dpi' parameter to specify absolute dimensions of the target image.

pdf2image -p secret -o ex3 --hres 1000 --vres 1000 -f tif --verb 3 test/blue_secret.pdf

Example 4. Convert PDF to multi-page TIFF.

To convert a PDF file to a multi-page TIFF, you can use the following lines:

pdf2image -o OUT2 --multipage -f tif --gray --verb 4 D:\

pdf2image --subfolders -o OUT2 --multipage -f tif --verb 3 "D:\MyPDF"

Batch Processing and the Use of Wildcards

PDF2Image supports processing of multiple input documents in the same run. For example, it is possible to specify multiple PDF folders and PDF2Image will automatically process all PDF documents matching a given file extension. For example, the following command-line will process all PDF documents in folders 'test1' and 'test2'

c:\>pdf2image -o c:/output_folder c:/test1 c:/test2

Wildcard characters can also be used to process multiple input files.

For example, if a directory contains the following PDF documents:

sh

1C:\test1 >dir
2 Directory of C:\test1
3 01/04/2007 03:35 PM <DIR> .
4 01/04/2007 03:35 PM <DIR> ..
5 05/21/2004 02:27 PM A1.pdf
6 05/03/2005 09:38 AM A2.pdf
7 05/20/2003 08:46 AM B1.pdf
8 05/15/2003 12:50 PM B2.pdf

To process all PDF documents in this folder, you could specify:

pdf2image -o c:/output_folder c:/test1/*.pdf

To process all PDF documents starting with 'A', you could specify:

pdf2image -o c:/output_folder c:/test1/A*.pdf

Or to process all PDF documents ending with '1', you could specify:

pdf2image -o c:/output_folder c:/test1/*1.pdf

You can use either of the two standard wildcards --- the question mark (?) and the asterisk (*) --- to specify filename and path arguments on the command line.

The wildcards are expanded in the same manner as operating system commands. (Please refer to your operating system user's guide if you are unfamiliar with wildcards). Enclosing an argument in double quotation marks (" ") suppresses the wildcard expansion. Within quoted arguments, you can represent quotation marks literally by preceding the double-quotation-mark character with a backslash (\). If no matches are found for the wildcard argument, the argument is passed literally.\

Exit Codes

To provide additional feedback, PDF2Image returns exit codes after completing processing. The exit codes can be used to provide user feedback, for logging etc. This is particularly important for applications running in an unattended environment.

The following table lists possible exit codes and their description:

sh

1Exit Code Description
2--------------- ------------------------------------------------------------------
30 All files converted successfully.
41 Document is secured. Need a valid password to open the document.
52 Error opening the input file(s).
63 An unknown exception encountered.

All codes other then '0' indicate that there was an error during the conversion process.

The following illustrates a sample Windows batch script that processes exit codes:

sh

1@echo off rem convert all PDF files in 'data' folder
2pdf2image ./data
3if errorlevel 1 goto passwd
4if errorlevel 2 goto inputerr
5if errorlevel 3 goto othererror
6if errorlevel 0 goto exit
7
8:passwd
9echo **Document is protected. Need a valid password to open the
10document**.
11goto exit
12
13:inputerr
14echo No input files specified.
15goto exit
16
17:othererror
18echo An error encountered during processing.
19goto exit
20
21:exit

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales