Please choose a menu option
Visit the IDRsolutions WebSite

High resolution PDF to image conversion

Description Automatic PDF to image conversion of PDF pages to hires images.
Jar Path org.jpedal.examples.images.HiResThumbnailExtractor

Click for source code link

How to run the code

Windows: java -cp %jpedalDir%/jpedal.jar org/jpedal/examples/images/HiResThumbnailExtractor pdfFilepath "jpg"
MacOS X Linux: java -cp $jpedalDir/jpedal.jar org/jpedal/examples/images/HiResThumbnailExtractor pdfFilepath "jpg"pdfFilepath "jpg"

This example would create thumbnails of the best possible quality on pages with downsampled images. 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.

The example includes a number of options to choose the best strategy to fit your requirements (set a desired pageSize, choose a maximum scaling, etc) so we strongly recommend you view the code.

First Parameter: The full path including the name and extension of the target PDF file.
Second Parameter: The output image file type. Choices are tif, jpg and png.

Tiff compression and jpeg dpi settings can be set via JVM options.

 

Important note on Jpegs

If you save the image as jpg the BufferedImage will need to be converted to sRGB. This is done in the example, but requires more memory.

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.

 

Quick way to get a scaled BufferedImage of a page in Java

If you just want a quick way to get a scaled page from a PDF file, all you need is to call the static method HiResThumbnailExtractor.getHiresPage(int pageNo, int scaling, String pdfFile)

 

How to control image color depth

It is possible to control the color depth of the ouput image using the System property

-Dorg.jpedal.imageType

The value of this variable should match the value of one of the awt.image.BufferedImage static TYPE variables. That variable will be used when creating the output image.

 

Other details/screenshot

PDF to Jpeg

This program has the following features:

  • Extracts every page in a PDF file as a separate image. 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.

 

Thread safe hires PDF to image conversion

If you use the method PdfDecoder.getPageAsHiRes() whilst also passing in additional parameters to JPedal using the static method PdfDecoder.modifyJPedalParameters(Map values) then this isn't guaranteed to be thread safe.

To extract hires images while also passing in additional parameters, please pass the additional parameters directly into one of the two getPageAsHiRes (getPageAsHiRes(int pageIndex, Map params) or getPageAsHiRes(int pageIndex, Map params, boolean isTransparent)).

Possible additional parameters are:

  • JPedalSettings.EXTRACT_AT_BEST_QUALITY_MAXSCALING
  • JPedalSettings.EXTRACT_AT_PAGE_SIZE
  • JPedalSettings.PAGE_SIZE_OVERRIDES_IMAGE

If using one of these two methods, DO NOT call PdfDecoder.modifyJPedalParameters(Map values) with any of the above parameters. Only pass values for these parameters directly into the getPageAsHiRes method.

For more information about passing additional parameters into JPedal, see here.

 

Faster PNG generation

There is a JVM flag org.jpedal.fasterPNG to speedup PNG generation.See JVM options for full details.

 

Links to related articles

Getting started tutorial
JPedal options can also be set via your code.
JVM options for full details of JVM settings which can enable JAI, set jpeg dpi and compress Tiffs
Additional optional libraries lists items which may be needed for some PDF files or functionality.
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.
Create separate images for Text, image and Vector graphics layers
Blog article on images explains how it all works

 

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

 


PDF viewer