Convert EPUB to JPG in Python – Aspose.HTML for Python via .NET

EPUB is an open XML-based format for digital books and publications designed for optimal viewing on various devices. Converting EPUB files to other formats is often necessary to leverage different capabilities and features of those formats. JPG files can contain high-quality image data with lossless compression. This unique compression feature allows to quickly and efficiently share JPG images and use them widely on the Web, computers, and mobile devices. With Aspose.HTML for Python via .NET, you can convert EPUB to JPG format programmatically with full control over a wide range of conversion parameters.

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

Online EPUB Converter

You can convert EPUB to other formats with Aspose.HTML for .NET API in real time. First, load an EPUB file from your local drive or URL and then run the example. The save options in the example are set by default. You will immediately receive the conversion result as a separate file.

                
            

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

Convert EPUB to JPG

To convert EPUB to JPG using ImageSaveOptions, 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 with JPEG image format. 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 convert EPUB to JPG. In the following example, you need to pass the EPUB file stream, ImageSaveOptions, and output file path to the convert_epub() method.

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

 1import os
 2from aspose.html.converters import *
 3from aspose.html.saving import *
 4from aspose.html.drawing import *
 5
 6# Setup directories and define paths
 7output_dir = "output/"
 8input_dir = "data/"
 9if not os.path.exists(output_dir):
10    os.makedirs(output_dir)
11document_path = os.path.join(input_dir, "input.epub")
12save_path = os.path.join(output_dir, "epub-to-image.jpeg")
13
14# Open an existing EPUB file for reading
15with open(document_path, "rb") as stream:
16
17    # Create an instance of ImageSaveOptions
18    options = ImageSaveOptions()
19    options.format.JPEG
20    options.horizontal_resolution = Resolution.from_dots_per_inch(200.0)
21    options.vertical_resolution = Resolution.from_dots_per_inch(200.0)
22    options.css.media_type.PRINT
23
24    # Convert EPUB to JPG
25    Converter.convert_epub(stream, options, save_path)

Save Options – ImageSaveOptions Class

The ImageSaveOptions class in Aspose.HTML for Python via .NET offers extensive customization options for converting EPUB content to various image formats, ensuring high-quality output tailored to your needs. Here’s a more detailed description of each property of ImageSaveOptions:

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.

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

Text “EPUB to JPG Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.