PDF Clipped Image Extraction
| Description | This program extracts all clipped images from a PDF at the highest possible quality and generates copies in user configurable sizes. |
| Jar Path | org.jpedal.examples.images.ExtractClippedImages |
How to run the code
| Windows: | java -Dorg.jpedal.logging=true -cp %libDir%/bcprov-jdk14-119.jar; %libDir%/jai_core.jar; %libDir%/jai_codec.jar; %jpedalDir%/jpedal.jar org/jpedal/examples/images/ExtractClippedImages raw processed log.txt 142 small 213 medium -1 unscaled |
| MacOS X Linux: | java -Dorg.jpedal.logging=true -cp $libDir/bcprov-jdk14-119.jar: $libDir/jai_core.jar: $libDir/jai_codec.jar: $jpedalDir/jpedal.jar org/jpedal/examples/images/ExtractClippedImages raw processed log.txt 142 small 213 medium -1 unscaled |
This example creates three versions of each image using the above example would use the code above. 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.
| First Parameter: | The name of the directory containing the PDF files to be processed. |
| Second Parameter: | The name of the directory to place PDF files once they have been used. |
| Third Parameter: | The name of the log file used to record all details. |
| Fourth parameter: | Any number of paired values giving the height in pixels for scaled images and the name of the directory to save the image in. Height of -1 means no scaling. |
The following command "raw processed log.txt 142 small 213 medium -1 unscaled" will process all files in JPedal subdirectory called raw, will place processed files in a JPedal subdirectory called processed and will provide a log of all operations performed in the file log.txt.
The files created will be: one 142 pixel high image in a subdirectory called small, one 213 pixel high image in a subdirectory called medium, and one unscaled (-1) image in a subdirectory called unscaled.
Other details/screenshot
This program has the following features:
- Fully automated.
- Hires image Extraction and clipping.
- Bicubic rescaling.
- User selectable output location.
- Proper clipping of image
- User selectable output image format.
Important notes on transparency, tifs and color matching
Unlike Acrobat, which saves the image and surrounding page, JPedal will properly clip the image and give it a transparent background. Jpegs do not support transparency so the image is saved with a white background. To preserve transparency, we recommend you save images as a png or tif which fully support transparency.
Java offers several libraries with differing levels of Tiff support. By default, Java's internal ImageIO libraries are used. Java also offers the JAI libraries which have better support and allows Tiff compression. If you have these on the classpath, JPedal can be instructed to use them (it is not a default) with a command line parameter. This needs to be switched on - see JVM option.
![]() |
Image processing can be memory intensive so may require -Xmx option to be used to increase memory usage |
Links to related articles
Additional optional libraries lists items which may be needed for some PDF files or functionality.
The flag -Dorg.jpedal.imageType=png allows you to alter the imageType from default of Tiff to png or jpeg. The flag -Dorg.jpedal.logging=true tells JPedal to write messages to the logfile. See JVM options for full details.
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





