Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert EPUB to JPG in Java, open the EPUB file as an input stream, create ImageSaveOptions with ImageFormat.Jpeg, and call
Converter.convertEPUB(). Use the save options to configure resolution, page size, margins, smoothing, and background color.
An EPUB file packages HTML, CSS, images, and other publication resources. Converting EPUB to JPG produces raster output that can be used in previews, presentations, and other workflows that require image files. JPG uses lossy compression and does not support transparency, so select an appropriate background color when needed.
The following example opens an EPUB stream and passes it with JPEG save options and an output path to Converter.convertEPUB():
1// Convert EPUB to JPG using Java
2
3// Open an existing EPUB file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub");
5
6// Invoke the convertEPUB() method to convert EPUB to JPG
7Converter.convertEPUB(fileInputStream, new ImageSaveOptions(ImageFormat.Jpeg), "convert-in-two-lines.jpg");The example reads input.epub and saves the result as convert-in-two-lines.jpg.
Follow these steps for a basic EPUB-to-JPG conversion:
FileInputStream.ImageFormat.Jpeg.Converter.convertEPUB(stream, options, outputPath) to convert EPUB to JPG.In this example, the source is input.epub, and the result is saved as input-output.jpg.
1// Convert EPUB to JPEG using Aspose.HTML for 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.Jpeg);
8
9// Call the сonvertEPUB() method to convert EPUB to JPG
10Converter.convertEPUB(fileInputStream, options, "input-output.jpg");Download complete examples and data files from GitHub.
For JPG output, the ImageSaveOptions settings used most often control the image format, page background, page dimensions, resolution, and smoothing.
| Method | Use it to |
|---|---|
setFormat(value) | Select the output image format. The default is PNG, so choose ImageFormat.Jpeg for JPG. |
setBackgroundColor(value) | Set the color that fills each output page. The default is transparent. |
getPageSetup() | Access the page setup used to configure output page size and margins. |
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 additional settings, see Fine-Tuning Converters.
Use ImageSaveOptions when the JPG output requires custom rendering settings:
ImageSaveOptions with ImageFormat.Jpeg and configure the required image settings.Converter.convertEPUB(stream, options, outputPath) to convert EPUB to JPG.The following example converts input.epub to input-options.jpg with high-quality smoothing, 400 dpi resolution, an Alice Blue background, and an 800 × 500 pixel page with custom margins:
1// Convert EPUB to JPG 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(ImageFormat.Jpeg);
8options.setSmoothingMode(SmoothingMode.HighQuality);
9options.setHorizontalResolution(Resolution.to_Resolution(400));
10options.setVerticalResolution(Resolution.to_Resolution(400));
11options.setBackgroundColor(Color.getAliceBlue());
12options.getPageSetup().setAnyPage(new Page(new Size(800, 500), new Margin(30, 20, 10, 10)));
13
14// Convert EPUB to JPG
15Converter.convertEPUB(fileInputStream, options, "input-options.jpg");Yes. Use the free online EPUB to JPG 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.
JPG does not support transparency. Set a background color in ImageSaveOptions when the EPUB design contains transparent page areas and the default replacement color is not appropriate for the output.
Use the free online EPUB to JPG 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.