Java PDF to image conversion
| Description | Automatic PDF to image conversion in java. |
| Jar Path | org.jpedal.examples.images.ExtractPagesAsThumbnails |
Click for java source code link
How to run the code
| Windows: | java -cp %jpedalDir%/jpedal.jar org/jpedal/examples/images/ExtractPagesAsThumbnails pdffiles png 50 |
| MacOS X Linux: | java -cp $jpedalDir/jpedal.jar org/jpedal/examples/images/ExtractPagesAsThumbnails pdffiles png 50 |
This example would create thumbnails of PDF pages as png files at 50% . In the demo version, there will be a red cross on the image.
Click here for help on running Java programs from the command line
An explanation of the command line parameters
This program accepts a number of command line parameters which define the ouput specifications. These are highlighted in red in the example code above. By default all output is placed in a JPedal subdirectory called thumbnails.
| First Parameter: | The name if the directory containing the PDF files to be processed. |
| Second Parameter: | The output image file type. Choices are tif, jpg and png. |
| Third Parameter: | The percentage scaling to perform. Values accepted are 1 to 100 (For over 100% we recommend using HiResThumbnailExtractor) |
Other details
This program has the following features:
- Extracts every page in a PDF file as a separate image (image can be in single Tif). The size of the thumbnail is user definable.
- Fully automated.
- Each thumbnail is extracted as a separate file.
- Choice of image output as either png, tif or jpg.
- Bicubic rescaling for the highest possible image quality.
- User selectable output image format.
JPEG image quality/compression
The compression quality of the JPEGs produced can be controlled with the JVM flag org.jpedal.compression_jpeg=value where org.jpedal.compression_jpeg=0 produces very poor, small files, org.jpedal.compression_jpeg=1 produces very large, high quality files and values inbetween produces a tradeoff.
Producing compressed or Multi-image Tiffs
This simply requires some additional JVM parameters. Here is example code for Windows modified with new values
java.exe -Dorg.jpedal.multipage_tiff=true -Dorg.jpedal.compress_tiff=true -Dorg.jpedal.jai=true -cp C:\jpedal\jpedal.jar; C:\ jpedal\lib\jai_core.jar; C:\jpedal\lib\jai_codec.jar; C:\jpedal\lib\jai_imageio.jar org/jpedal/examples/images/ExtractPagesAsThumbnails C:\jpedal\testPDF.pdf tif
-Dorg.jpedal.jai=true tells JPedal to use JAI (needed for both features). JAI must also be on the classpath.
-Dorg.jpedal.compress_tiff=true Use Tif compression to reduce filesize.
-Dorg.jpedal.multipage_tiff=true Store all images in a single Tif file.
Links to related articles
Getting started tutorial
JVM options for full details of JVM settings which can enable JAI and compress Tiffs
Additional optional libraries lists items which may be needed for some PDF files or functionality.
HiResThumbnailExtractor is slower but will use the raw images (if bigger than the page) and scale the PDF page up rather than scale the images down.
Create separate images for Text, image and Vector graphics layers
PDF to image conversion Java example code provides just the very bare code needed which you can cut and paste directly into your Java code.
Return to main PDF support section
Click here for the main PDF support area with lots of java examples, PDF tutorials and useful information to get the most out of the JPedal PDF library



