Convert EPUB to PNG in Python

PNG file format supports lossless image compression that makes it popular among its users. It widely takes to transmit pictures over the network, display photos and graphics on web pages and reserve in cloud storages. With Aspose.HTML for Python via .NET, you can convert EPUB to PNG format programmatically with full control over a wide range of conversion parameters.

In this article, you find information on how to convert EPUB to PNG using convert_epub() methods of the Converter class and how to apply ImageSaveOptions.

To continue following this tutorial, install and configure Aspose.HTML for Python via .NET in your Python project.

Online EPUB Converter

You can test the Aspose.HTML for Python via .NET API functionality and convert EPUB in real-time. Please load an EPUB file from a local file system or URL, select the output format and run the example. In the example, the save options are set by default. You will immediately receive the result as a separate file.

                
            

If you want to convert EPUB to PNG using ImageSaveOptions programmatically, please see the following Python code example.

Convert EPUB to PNG

Using convert_epub() methods is the most common way to convert EPUB files into various formats. To convert EPUB to PNG with ImageSaveOptions specifying, you should follow a few steps:

  1. Open an existing EPUB file. In the example, we use the open() method to open and read an EPUB file from the file system at the specified path.
  2. Create a new ImageSaveOptions object. By default, the format property is PNG. Here, you can set the required save options, such as page setup or resolution.
  3. Use one of the convert_epub() methods of the Converter class to save EPUB as a PNG image.

Look at the following Python code snippet that shows how to convert EPUB to PNG with custom save options using Aspose.HTML for Python via .NET.

 1# Convert EPUB to PNG using Python with custom settings
 2
 3import os
 4import aspose.html.converters as conv
 5import aspose.html.saving as sav
 6import aspose.html.drawing as dr
 7import aspose.pydrawing as pd
 8
 9# Setup directories and define paths
10output_dir = "output/"
11input_dir = "data/"
12os.makedirs(output_dir, exist_ok=True)
13
14document_path = os.path.join(input_dir, "input.epub")
15save_path = os.path.join(output_dir, "epub-to-image.png")
16
17# Open an existing EPUB file for reading
18with open(document_path, "rb") as stream:
19
20    # Create an instance of ImageSaveOptions
21    options = sav.ImageSaveOptions()
22    options.horizontal_resolution = dr.Resolution.from_dots_per_inch(150.0)
23    options.vertical_resolution = dr.Resolution.from_dots_per_inch(150.0)
24    options.page_setup.any_page.size = dr.Size(500, 1000)
25    options.css.media_type.SCREEN
26    options.text.use_hinting = True
27
28    # Convert EPUB to PNG
29    conv.Converter.convert_epub(stream, options, save_path)

Save Options – ImageSaveOptions Class

The PNG images creation functionality can be enhanced with save options per your needs. Aspose.HTML for Python via .NET allows converting HTML to PNG using default or custom save options. The ImageSaveOptions class offers extensive customization for converting EPUB content into image formats. Here’s a more detailed description of each property of ImageSaveOptions:

See Also

  • Download the Aspose.HTML for Python via .NET library to successfully, quickly, and easily convert your HTML, MHTML, EPUB, SVG, and Markdown documents to the most popular formats.

  • You can download the complete examples and data files from GitHub.

  • Aspose.HTML offers a free online EPUB to PNG Converter that converts EPUB to PNG image with high quality, easy and fast. Just upload, convert your files and get results in a few seconds!

Text “EPUB to PNG Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.