Render your PDF as an Image in Java

JPedal renders PDF files as BMP, GIF, HEIC, JPEG, JPEG2000, PNG, TIFF or WEBP image files or Thumbnails

Render your PDF as an Image or Thumbnail with this Java code

ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".bmp");
            // Setters to control output
            final BmpEncoderOptions options = new BmpEncoderOptions();
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".gif");
            // Setters to control output
            final GifEncoderOptions options = new GifEncoderOptions();
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".heic");
            // Setters to control output
            final HeicEncoderOptions options = new HeicEncoderOptions();
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".jpg");
            // Setters to control output
            final JpegEncoderOptions options = new JpegEncoderOptions();
            options.setQuality(90); // Default is 75. No compression is 100
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".jpx");
            // Setters to control output
            final Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions();
            options.setOutputSubtype(Jpeg2000OutputSubtype.JPX); // Default is JPX. JP2 also
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".png");
            // Setters to control output
            final PngEncoderOptions options = new PngEncoderOptions();
            options.setCompressionFormat(PngCompressionFormat.NONE);
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".tiff");
            // Setters to control output
            final TiffEncoderOptions options = new TiffEncoderOptions();
            options.setCompressionFormat(TiffCompressionFormat.DEFLATE);
            options.setResolutionUnit(TiffResolutionUnit.INCH);
            options.setXResolution(300);
            options.setYResolution(300);
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".webp");
            // Setters to control output
            final  options = new ();
            options.setQuality(90); // Default is 75. No compression is 100
            options.setCompressionFormat(WebpCompressionFormat.LOSSLESS); // Also supports LOSSY
            JDeli.write(bi, options, out);
        }
    }
} catch (PdfException | IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
convert.closePDFfile();
// Disable all caching to file to reduce memory usage
PdfFileReader.alwaysCacheInMemory = -1;
// bytes is a byte[] with the PDF file data
ConvertPagesToImages convert = new ConvertPagesToImages(bytes);
// convert.setPassword("password"); // If password needed
convert.setPageScaling(1.0f);
try {
    if (convert.openPDFFile()) {
        int pageCount = convert.getPageCount();
        for (int page = 1; page <= pageCount; page++) {
            BufferedImage image = convert.getPageAsImage(page);
        }
    }
} catch (PdfException e) {
    e.printStackTrace();
}
convert.closePDFfile();

JPedal allows us to render PDF page as images very quickly and efficiently.

- G. Barth (CTO Counsel Press)

JPedal PDF Rendering Key Features

JPedal allows developers to render the pages of PDF Documents as high quality Images.

Image Output Formats

Our Java PDF renderer can write to BMP, GIF, HEIC, JPEG, JPEG2000, PNG, TIFF (single and multipage), WebP and BufferedImage.

Image Size Settings

JPedal allows precise control over image output size, including options to upscale and downsample.

In-memory PDF rendering

JPedal can be setup to perform the rendering totally in memory for maximum speed or security.

Outstanding Performance

The Java PDF renderer library is 3-4 times faster than other alternatives, with lower memory usage.

No other dependencies

JPedal just needs Java to run. It does not use any other native or Java libraries.

Java support

JPedal works with Java 17 and above and is tested on all new Java releases.

JPedal has the advantage of running in the same Java virtual machine, so we save a lot of CPU resources.

- T. Büngener (Software Architect InSign)

Why JPedal?

1.

Actively developed commercial library with full support and no third party dependencies.

2.

Process PDF files up to 3x faster than alternative Java PDF libraries.

3.

Simple licensing options and source code access for OEM users.

Try JPedal now