
TL;DR:
Java cannot read PDF files on its own. With JPedal you open the PDF, render each page to a BufferedImage, then write it out with JDeli.write(). BMP is normally uncompressed, so the files are very large and there is no quality setting to trade against size. Use it for Windows interop and legacy tooling; for anything else PNG is lossless too and a fraction of the size.
Why convert PDF files to BMP images?
A PDF is a vector image (so it is rendered when you display it at whatever size you specify). A BMP is a lossless bit-mapped file of a set size with fixed values. So to convert a PDF to a BMP file we need to create a blank image and then draw the PDF onto this.
This process is usually done with a PDF tool such as Acrobat however, our Java PDF library includes added functionality. There are lots of Open Source and commercial tools in most major languages. If you are using Java, it is not a function that is built into Java – you will need an external application to do this such as our JPedal PDF library. JPedal is the best Java PDF library for developers.
Add JPedal to your project
JPedal is published to the IDRsolutions Maven repository. Add the repository and the dependency to your build, or download the trial jar and put it on your class or module path.
Maven
<repositories>
<repository>
<id>IDRsolutions</id>
<name>IDR Solutions</name>
<url>https://maven.idrsolutions.com</url>
</repository>
</repositories>
<dependency>
<groupId>com.idrsolutions</groupId>
<artifactId>jpedal-trial</artifactId>
<version>YYYY.MM</version>
</dependency>
Gradle
repositories {
maven { url 'https://maven.idrsolutions.com' }
}
dependencies {
implementation 'com.idrsolutions:jpedal-trial:YYYY.MM'
}
The repository needs your trial token or customer credentials in ~/.m2/settings.xml — see the Maven setup guide. Paid releases use the jpedal artifact in place of jpedal-trial.
How to convert PDF to BMP in Java
- Download a trial copy of JPedal and add it to your IDE.
- Create a File handle, InputStream or URL pointing to the PDF file
- Include a password if file password protected
- Open the PDF file
- Iterate over the pages
and the Java code to convert PDF to BMP…
ConvertPagesToImages convert = new ConvertPagesToImages("inputFile.pdf");
//convert.setPassword("password");
if (convert.openPDFFile()) {
for (int page = 1; page <= convert.getPageCount(); page++) {
final BufferedImage bi = convert.getPageAsImage(page);
final File out = new File("outputFolder" + page + ".bmp");
JDeli.write(bi, OutputFormat.BMP, out);
}
}
convert.closePDFfile();
You can read our PDF to BMP conversion guide for more information on the available conversion options and Java code examples.
Controlling the resolution and DPI of the output
This is the setting that matters most, and the one that is easiest to get wrong. Output resolution is controlled with setPageScaling(). The PDF to BMP documentation gives three reference points:
convert.setPageScaling(1.0f); // 72 DPI - the default
convert.setPageScaling(1.33f); // which gives same size as Acrobat at 100% (approx 96 DPI)
convert.setPageScaling(2.0f); // 144 DPI
Scaling and resolution are directly proportional, because a PDF page is defined in points at 72 points per inch. For any other target, the scaling factor is targetDpi / 72:
final int targetDpi = 300; // 150 DPI -> 2.08f, 300 DPI -> 4.17f, 600 DPI -> 8.33f
convert.setPageScaling(targetDpi / 72f);
150 DPI is a reasonable default for screen and web output, and 300 DPI is the usual minimum for print.
If you need a fixed output size instead — for thumbnails, for example — use setFitToSize(). JPedal preserves the aspect ratio and fits the page within the given dimensions:
convert.setFitToSize(new int[] {300,400});
You can also restrict the conversion to particular pages rather than rendering the whole document:
convert.setPageRange(new PageRanges("1-5,8:10,15"));
Watch the memory cost. Scaling applies in both directions, so doubling the DPI quadruples the pixel count. An A4 page is about 595 × 842 pixels at 72 DPI, but roughly 2480 × 3508 at 300 DPI — around 35 MB as an uncompressed 32-bit BufferedImage. Render and write one page at a time rather than collecting a whole document in a list.
BMP has no compression to fall back on, so the DPI decides the file size on its own and the arithmetic is brutal. An A4 page at 72 DPI is about 595 × 842 pixels, or roughly 2 MB at 32 bits per pixel. The same page at 300 DPI is about 2480 × 3508 pixels — around 35 MB, for one page. Output settings are configured with BmpEncoderOptions:
final BmpEncoderOptions options = new BmpEncoderOptions();
JDeli.write(bi, options, out);
Pick the lowest DPI that still meets your requirement, and if the destination can read anything else, use PNG: it is also lossless, but a typical page compresses to a small fraction of the BMP size. The only change needed is the OutputFormat constant.
Which image format should you use?
The conversion code is the same for every output format — only the OutputFormat constant and the file extension change. The trade-offs are not the same, so it is worth checking that BMP is the right choice:
| Format | Compression | Transparency | Multi-page | Best for |
|---|---|---|---|---|
| PNG | Lossless | Yes | No | Text-heavy pages, thumbnails, screenshots, anything that will be zoomed |
| JPEG | Lossy | No | No | Photographic or scanned pages where file size matters more than sharp text |
| TIFF | Lossless (LZW, Deflate) or JPEG | Yes | Yes | Archival and document workflows, and whole documents in a single file |
| GIF | Lossless, 256 colours only | 1-bit only | Yes (animation) | Legacy pipelines only — the colour limit makes it a poor fit for PDF pages |
| BMP | None (uncompressed) | No | No | Windows interop and legacy tooling that cannot read anything else |
| WebP | Lossy or lossless | Yes | No | Web delivery — usually smaller than both PNG and JPEG |
| HEIC | Lossy or lossless | Yes | Yes | Apple ecosystems and the smallest lossy files |
Key points to remember
The usual reason for doing this conversion is to display the content as an image (e.g. a thumbnail on a website). However, there are things so remember:
1. Bitmapped images do not scale very well (unlike Vector formats like PDF). So you need to get the size correct. If you make it too small you will not be able to zoom in without pixelation. If you make it too big you will make the download slower and need more memory.
2. Bitmapped images do not have some of the other advantages of PDF files (like text search). You may need to add manual functionality to your application if you wish to have things like text highlighting.
3. If you are doing it to print the PDF you will need a very large image to get a quality print at 300 or 600 dpi (what looks good on screen at 72dpi will not appear as crisp on a printout).
So long as you remember these, Java PDF to BMP conversion is a straightforward process with a tool such as JPedal.
Frequently asked questions
Why are my BMP files so large?
BMP is normally stored uncompressed, so the file is close to width × height × bytes-per-pixel with no saving at all. A 300 DPI A4 page comes out at roughly 35 MB. PNG stores the same pixels losslessly in a fraction of the space.
When is BMP actually the right choice?
When something downstream requires it — Windows interop, older imaging or scanning tooling, or a system that reads raw bitmaps directly. If you are free to choose, PNG gives you the same lossless pixels in a much smaller file.
What DPI should I use when converting a PDF to BMP?
150 DPI is a good default for screen and web use, and 300 DPI is the usual minimum for print. Set it with convert.setPageScaling(targetDpi / 72f), because PDF pages are defined at 72 points per inch. Remember that the pixel count grows with the square of the scaling factor.
Can I convert only some of the pages?
Yes. Call convert.setPageRange(new PageRanges("1-5,8:10,15")) before you open the file. Without it, every page in the document is rendered.
How do I convert a password-protected PDF?
Call convert.setPassword("password") before openPDFFile(). The same applies to both the owner and the user password.
Can Java convert a PDF to an image without a third-party library?
No. The JDK has no PDF support at all — ImageIO can write BMP files, but nothing in the standard library can parse or render a PDF page. You need a PDF library such as JPedal, Apache PDFBox or a Ghostscript wrapper to produce the BufferedImage in the first place.
Other useful PDF to BMP resources
- Java PDF to Image conversion — the full guide to every output format
- Java PDF to PNG conversion
- Java PDF to JPEG conversion
- Java PDF to TIFF conversion
- Java PDF to WebP conversion
- Java PDF to HEIC conversion
- Java PDF to GIF conversion
- JPedal PDF to BMP documentation
Converting to a different format, or not sure which one you need? Our Java PDF to Image conversion guide covers every output format JPedal supports, and we bring over two decades of hands-on experience to helping you work with PDF files in Java.