For common raster images, use Java’s ImageIO with Java 2D to create a proportional thumbnail, or use Thumbnailator for a shorter fluent implementation. PDFs require a PDF-aware renderer such as Apache PDFBox; ImageIO does not render PDF pages. Choose a bounded resize when you want consistent maximum dimensions without stretching, and crop only when the design calls for a fixed composition.
Choose the conversion path for your input
| Input or use case | Suitable path | Why |
|---|---|---|
| Common raster image files | JDK ImageIO and Java 2D |
Standard-library reader and writer foundation with control over scaling and output. |
| Raster thumbnails with less implementation code | Thumbnailator | Fluent API for bounded resizing, rotation, watermarking, and output-quality settings. |
| PDF page previews | Apache PDFBox | PDF-aware page rendering or image-object APIs; a PDF is not an ordinary raster image. |
| Build-time batch processing | Apache Ant Image task | Build automation task with proportional scaling and destination/filename mapping options. |
The right choice depends on the input format, whether a third-party dependency is acceptable, how much control you need over cropping and encoding, and your memory and latency limits.
Create a raster thumbnail with Java ImageIO
ImageIO is Java’s standard entry point for reading and writing common image formats. Oracle’s Java SE 26 documentation describes the API and standard BMP and GIF plug-ins: Java Image I/O package documentation. Use Java 2D to scale the decoded image, then write the resulting BufferedImage.
Scale proportionally into a bounding box
To avoid stretching, calculate the same scale factor for both dimensions. For a source of width w and height h, and maximum output dimensions maxW and maxH, use scale = min(maxW / w, maxH / h). Multiply both source dimensions by that factor and round to integer pixel dimensions. This fits the image inside the box while preserving its aspect ratio; one dimension may be smaller than the maximum.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches#1 Best Overall
- PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
- QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
- VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
- INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
- EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
The following example uses a high-quality Java 2D interpolation hint. The precise scaling algorithm is an implementation choice, not a promise made by the ImageIO API.
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ThumbnailMaker {
public static void createThumbnail(File input, File output,
int maxWidth, int maxHeight,
String format) throws IOException {
BufferedImage source = ImageIO.read(input);
if (source == null) {
throw new IOException("Unsupported or unrecognized image: " + input);
}
double scale = Math.min(
(double) maxWidth / source.getWidth(),
(double) maxHeight / source.getHeight()
);
int width = Math.max(1, (int) Math.round(source.getWidth() * scale));
int height = Math.max(1, (int) Math.round(source.getHeight() * scale));
int type = format.equalsIgnoreCase("png")
? BufferedImage.TYPE_INT_ARGB
: BufferedImage.TYPE_INT_RGB;
BufferedImage thumbnail = new BufferedImage(width, height, type);
Graphics2D graphics = thumbnail.createGraphics();
try {
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.drawImage(source, 0, 0, width, height, null);
} finally {
graphics.dispose();
}
if (!ImageIO.write(thumbnail, format, output)) {
throw new IOException("No ImageIO writer available for: " + format);
}
}
}
Validate that the requested dimensions are positive before calculating the scale in production code. The sample’s RGB/ARGB choice is intentionally simple: consider the source color model and transparency requirements when selecting an output image type. A JPEG cannot retain transparency; PNG is a suitable choice when transparency or lossless output matters. JPEG is commonly used for photographic previews.
Rank #2
- FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
- ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
- READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
- WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
- OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)
Handle unsupported input and output
ImageIO.read can return null when no registered reader recognizes the input. Likewise, ImageIO.write returns false if no suitable writer is available. Check both outcomes rather than assuming that a file extension guarantees an available decoder or encoder. Select the output format explicitly and make sure the extension matches it.
Use Thumbnailator for a concise implementation
Thumbnailator is a Java thumbnail-generation library available from Maven Central. Its project documentation describes it as a single JAR without external-library dependencies and presents it as a way to simplify ImageIO, Java 2D, and image-scaling work: Thumbnailator project documentation.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Rank #3
- FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
- INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
- SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
- EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
- SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning
A bounded 160×160 example from the project preserves source proportions:
Thumbnails.of(new File("original.jpg"))
.size(160, 160)
.toFile(new File("thumbnail.jpg"));
size specifies a maximum bounding box, so the output need not be exactly 160 pixels in both dimensions. Thumbnailator’s documented API also includes rotation, watermarking, and output-quality controls: Thumbnailator usage examples. Use an explicit crop operation only when every result must have the same rectangular composition; cropping discards part of the original image.
Rank #4
- Scanner type: Document
- Connectivity technology: USB
- With Auto Scan Mode, the scanner automatically detects what you're scanning
- Digitize documents and images
Generate thumbnails from PDFs with PDFBox
A PDF contains document pages and objects, not a single raster image that ImageIO can read as a page preview. Use a PDF-aware library such as Apache PDFBox to render the selected page to a BufferedImage, then encode that image as JPEG or PNG. PDFBox documents PDImageXObject.createThumbnail and convenience methods for creating image objects from files or bytes; its documented raster support includes JPG/JPEG, TIF/TIFF, GIF, BMP, and PNG: PDFBox PDImageXObject API.
Keep page-rendering resolution separate from the final thumbnail dimensions. Rendering at an appropriate resolution and then scaling to the output box gives you control over detail and memory use; rendering a very large page image can consume substantially more memory than the final thumbnail. PDFBox’s newer API documentation also describes direct PNG handling where possible and notes that output-size behavior depends on PNG compression: PDFBox 3.0.0 PDImageXObject API.
Recommended Free Tools
Best Value
- OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
- CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
- STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
- PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
- AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss
Automate thumbnail creation during a build
If thumbnails belong in a build pipeline rather than application request handling, Apache Ant’s Image task uses AWT and ImageIO. Its manual shows proportional fit within 160×160 and width-based 40-pixel PNG thumbnails, with destination-directory and filename-mapping options: Apache Ant Image task. These are examples in the manual, not required output dimensions; choose values that suit the assets and interface.
Quick Recap
Choose output dimensions and format deliberately
- Preserve proportions for previews. Fit within a maximum width and height to avoid distortion. If the interface needs identical rectangular tiles, crop intentionally and position the crop to retain the subject.
- Choose JPEG for photographic previews when compact lossy output is acceptable. Use the selected writer’s quality controls if you need to tune the trade-off.
- Choose PNG when transparency or lossless output matters. PNG compression affects file size; it does not make a large rendered input image free to process.
- Account for decoded-image memory. A small output does not prevent a large source or high-resolution PDF page from taking significant memory during decoding or rendering. Set appropriate input and render limits for batch or untrusted files.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

