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 Python, open the EPUB file as a binary stream, create
ImageSaveOptions without a format argument, and call
Converter.convert_epub() with the stream, options, and output path. ImageSaveOptions() selects PNG by default.
PNG is a lossless raster image format that supports transparency. Converting EPUB to PNG is useful for page previews, illustrations, diagrams, and text-heavy document images where sharp edges should be retained.
Follow these steps for a basic EPUB-to-PNG conversion:
ImageSaveOptions() without a format argument because PNG is the default.Converter.convert_epub().1import aspose.html.converters as conv
2import aspose.html.saving as sav
3
4with open("input.epub", "rb") as stream:
5 options = sav.ImageSaveOptions()
6 conv.Converter.convert_epub(stream, options, "output.png")This example converts EPUB to PNG with the default page, resolution, background, CSS, and text-rendering settings.
Use ImageSaveOptions when the PNG output requires specific page dimensions, margins, resolution, or CSS media rules. The following example creates the output directory, configures the rendered page, and applies screen-media styles:
ImageSaveOptions() for PNG output.Converter.convert_epub(). 1import os
2import aspose.html.converters as conv
3import aspose.html.drawing as dr
4import aspose.html.saving as sav
5
6input_dir = "data"
7output_dir = "output"
8os.makedirs(output_dir, exist_ok=True)
9
10input_path = os.path.join(input_dir, "input.epub")
11output_path = os.path.join(output_dir, "epub-page.png")
12
13options = sav.ImageSaveOptions()
14options.horizontal_resolution = dr.Resolution.from_dots_per_inch(150.0)
15options.vertical_resolution = dr.Resolution.from_dots_per_inch(150.0)
16options.page_setup.any_page = dr.Page(
17 dr.Size(600, 800),
18 dr.Margin(20, 20, 20, 20)
19)
20with open(input_path, "rb") as stream:
21 conv.Converter.convert_epub(stream, options, output_path)The parameterless ImageSaveOptions constructor selects PNG. The custom example then configures the resolution, page dimensions, margins, antialiasing, and text hinting.
One EPUB can produce several PNG files when its content spans multiple rendered pages. Each file contains one page image; the converter does not combine an entire publication into one tall PNG.
| Property | Use it to control |
|---|---|
| format | Output image format. The parameterless constructor selects PNG by default. |
| page_setup | Page dimensions, margins, and layout. |
| horizontal_resolution and vertical_resolution | Raster output resolution. Higher values create more pixels and larger files. |
| background_color | Color behind the rendered page. The default is transparent. |
| css | CSS processing, including the media type used for media queries. |
| use_antialiasing | Smoothing of rasterized graphics. It is enabled by default. |
| text | Text-rendering settings such as font hinting. |
PNG uses lossless compression, so encoding the rendered page does not introduce JPEG-style compression artifacts. It is well suited to text, line graphics, diagrams, screenshots, and other content that benefits from sharp edges. The result remains a raster image and does not preserve editable EPUB text or reflow behavior.
PNG supports an alpha channel. Transparent areas can remain transparent when the EPUB and its CSS do not define an opaque page background. Set background_color only when a specific solid background is required. Increasing resolution creates more pixels but does not add detail to low-resolution source images stored in the EPUB.
| Issue | Likely cause and solution |
|---|---|
| Several PNG files are created | The EPUB spans multiple rendered pages. Each PNG stores one page image. |
| The background is opaque | The EPUB or its CSS defines a page background. Remove or change that declaration when transparent output is required. |
| The PNG files are unexpectedly large | Lossless images and high resolution increase file size. Choose only the resolution required by the destination workflow. |
| Content is clipped or surrounded by excessive space | Configure page dimensions and margins suitable for the EPUB layout through page_setup. |
EPUB content is paginated during rendering, while PNG is a single-page image format. The converter can therefore create one PNG file for each rendered page.
PNG supports transparency, and the default ImageSaveOptions.background_color is transparent. Transparent output is possible when the EPUB and its CSS do not define an opaque page background.
Use the free online EPUB to PNG Converter for quick manual conversion without writing code. Use Aspose.HTML for Python via .NET when EPUB-to-PNG conversion must run programmatically in an application, service, or batch workflow.
Download complete examples and data files from GitHub.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.