Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
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.
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.
Follow these steps for a basic EPUB-to-PNG conversion:
FileInputStream.ImageSaveOptions with ImageFormat.Png. The parameterless constructor also uses PNG by default.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.
For PNG output, the ImageSaveOptions settings used most often control the output format, page background, resolution, and smoothing.
| Method | Use 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.
Use ImageSaveOptions when the PNG output requires custom rendering settings:
ImageSaveOptions and configure the required PNG settings.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");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.
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.
Use the free online EPUB to PNG Converter for quick manual conversion without writing Java code.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.