Convert EPUB to PNG in Java

To convert EPUB to PNG in Java, open the EPUB file as an input stream, create ImageSaveOptions with PNG output, and call Converter.convertEPUB(). PNG is the default ImageSaveOptions format and supports lossless image data and transparency.

Converting EPUB to PNG produces raster output for previews, presentations, documentation, and other image-based workflows. Aspose.HTML for Java uses ImageSaveOptions to select PNG and configure properties such as resolution, background color, and smoothing.

Convert EPUB to PNG in Two Lines of Java Code

The following example opens an EPUB stream and passes it with default ImageSaveOptions and an output path to Converter.convertEPUB():

1// Convert EPUB to PNG using Java
2
3// Open an existing EPUB file for reading
4FileInputStream inputStream = new FileInputStream("input.epub");
5
6// Convert EPUB to PNG
7Converter.convertEPUB(inputStream, new ImageSaveOptions(), "convert-with-single-line.png");

The example reads input.epub and saves the result as convert-with-single-line.png.

Convert an EPUB File to PNG

Follow these steps for a basic EPUB-to-PNG conversion:

  1. Open the source EPUB file as a FileInputStream.
  2. Create ImageSaveOptions with ImageFormat.Png. The parameterless constructor also uses PNG by default.
  3. Call Converter.convertEPUB(stream, options, outputPath) to convert EPUB to PNG.

In this example, the source is input.epub, and the result is saved as input-output.png.

 1// Convert EPUB to PNG in Java
 2
 3// Open an existing EPUB file for reading
 4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub");
 5
 6// Create an instance of the ImageSaveOptions class
 7ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Png);
 8
 9// Call the сonvertEPUB() method to convert EPUB to PNG
10Converter.convertEPUB(fileInputStream, options, "input-output.png");

Download complete examples and data files from GitHub.

Save Options – ImageSaveOptions Class

For PNG output, the ImageSaveOptions settings used most often control the output format, page background, resolution, and smoothing.

MethodUse it to
setFormat(value)Select the output image format. The default is PNG.
setBackgroundColor(value)Set the color that fills each output page. The default is transparent.
setHorizontalResolution(value)Set horizontal image resolution. The default is 300 dpi.
setVerticalResolution(value)Set vertical image resolution. The default is 300 dpi.
setSmoothingMode(value)Configure image rendering quality.

For page setup, margins, and additional image settings, see Fine-Tuning Converters.

Customize EPUB to PNG with ImageSaveOptions

Use ImageSaveOptions when the PNG output requires custom rendering settings:

  1. Open the source EPUB file as an input stream.
  2. Create ImageSaveOptions and configure the required PNG settings.
  3. Call Converter.convertEPUB(stream, options, outputPath) to convert EPUB to PNG.

The following example converts input.epub to input-options.png with an Alice Blue background, high-quality smoothing, and 400 dpi horizontal and vertical resolution:

 1// Convert EPUB to PNG in Java with custom settings
 2
 3// Open an existing EPUB file for reading
 4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub");
 5
 6// Initialize ImageSaveOptions
 7ImageSaveOptions options = new ImageSaveOptions();
 8options.setBackgroundColor(Color.getAliceBlue());
 9options.setSmoothingMode(SmoothingMode.HighQuality);
10options.setVerticalResolution(Resolution.to_Resolution(400));
11options.setHorizontalResolution(Resolution.to_Resolution(400));
12
13// Call the convertEPUB() method to convert EPUB to PNG
14Converter.convertEPUB(fileInputStream, options, "input-options.png");

Related EPUB Conversion Guides

Other Platforms

FAQ

Can I convert EPUB to PNG for free?

Yes. Use the free online EPUB to PNG Converter for a quick manual conversion. Aspose.HTML for Java is a commercial API for programmatic conversion and can be evaluated before licensing; see Licensing.

Does PNG output remain reflowable like an EPUB?

No. EPUB content can reflow according to a reader or viewport, while PNG stores fixed raster image data. Set the required resolution and rendering options before conversion because the resulting image does not reflow.

Try Online EPUB to PNG Conversion

Use the free online EPUB to PNG Converter for quick manual conversion without writing Java code.

Free Online EPUB to PNG Converter