Convert EPUB to GIF in C#
GIF is a popular image format that is frequently used in web publishing. With Aspose.HTML for .NET, you can convert EPUB to GIF format programmatically with full control over a wide range of conversion parameters. In this article, you find information on how to convert EPUB to GIF using ConvertEPUB() methods of the Converter class, and how to apply ImageSaveOptions and ICreateStreamProvider parameters.
Online EPUB Converter
You can check the Aspose.HTML API functionality and convert EPUB in real-time. Please load an EPUB file from the local file system, 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 GIF programmatically, please see the following C# code examples.
Convert EPUB to GIF
Using Converter.ConvertEPUB() methods is the most common way to convert EPUB files into various formats. You should follow a few steps:
- Open an existing EPUB file. In the example, we use the OpenRead() method of System.IO.FileStream class to open and read an EPUB file from the file system at the specified path.
- Create a new ImageSaveOptions object with GIF ImageFormat. By default, the Format property is PNG.
- Use the ConvertEPUB() method of the Converter class to save EPUB as a GIF image. You need to pass the EPUB file stream, ImageSaveOptions, and output file path to the ConvertEPUB() method for EPUB to GIF conversion.
Please take a look over the following C# code snippet which shows the process of converting EPUB to GIF using Aspose.HTML for .NET.
1// Open an existing EPUB file for reading
2using var stream = File.OpenRead(DataDir + "input.epub");
3
4// Prepare a path to save the converted file
5string savePath = Path.Combine(OutputDir, "input-output.gif");
6
7// Create an instance of the ImageSaveOptions class
8var options = new ImageSaveOptions(ImageFormat.Gif);
9
10// Call the ConvertEPUB() method to convert EPUB to GIF
11Converter.ConvertEPUB(stream, options, savePath);
You can download the complete examples and data files from GitHub.
Save Options
Aspose.HTML allows converting EPUB to GIF using default or custom save options. ImageSaveOptions usage enables you to tune the rendering process. You can specify the page size, margins, horizontal/vertical resolution, etc.
Property | Description |
---|---|
Compression | Sets Tagged Image File Format (TIFF) Compression. By default, this property is LZW. |
CSS | Gets a CssOptions object which is used for configuration of CSS properties processing. |
Format | Sets the ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default, this property is PNG. |
BackgroundColor | This property sets the color that will fill the background. By default, this property is Transparent. |
PageSetup | This property gets a page setup object and uses it for configuration output page-set. |
HorizontalResolution | Sets horizontal resolution for output images in pixels per inch. The default value is 300 dpi. |
VerticalResolution | Sets vertical resolution for output images in pixels per inch. The default value is 300 dpi. |
UseAntialiasing | This property sets the image rendering quality. Antialiasing is enabled by default. |
Text | Gets a TextOptions object which is used for configuration of text rendering. |
To learn more about the ImageSaveOptions class, please read the Fine-Tuning Converters article.
Convert EPUB to GIF using ImageSaveOptions
To convert EPUB to GIF with ImageSaveOptions specifying, you should follow a few steps:
- Open an existing EPUB file.
- Create a new ImageSaveOptions object and specify save options.
- Use the ConvertEPUB() method of the Converter class to save EPUB as a GIF image. You need to pass the EPUB file stream, ImageSaveOptions, and output file path to the ConvertEPUB() method to convert EPUB to GIF.
The following C# code snippet shows how to convert EPUB to GIF using custom save options:
1// Open an existing EPUB file for reading
2using var stream = File.OpenRead(DataDir + "input.epub");
3
4// Prepare a path for converted file saving
5string savePath = Path.Combine(OutputDir, "input-options.gif");
6
7// Initialize ImageSaveOptions
8var options = new ImageSaveOptions(ImageFormat.Gif)
9{
10 UseAntialiasing = true,
11 HorizontalResolution = 400,
12 VerticalResolution = 400,
13 BackgroundColor = System.Drawing.Color.AliceBlue
14};
15options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(800, 500), new Margin(30, 20, 10, 10));
16
17// Call the ConvertEPUB() method to convert EPUB to GIF
18Converter.ConvertEPUB(stream, options, savePath);
The
ImageSaveOptions() constructor initializes an instance of the ImageSaveOptions class that is passed to ConvertEPUB() method. The ConvertEPUB() method takes the stream
, options
, output file path savePath
and performs the conversion operation.
In the example, we use:
HorizontalResolution
andVerticalResolution
properties that set horizontal/vertical resolution for output images in pixels per inch. By default, these properties are 300 dpi.UseAntialiasing
property that sets the rendering quality for this image.BackgroundColor
property that specifies the color that the background will be filled in. The default BackgroundColor is Transparent.PageSetup
property that specifies the page size and margins in pixels.
You can download the complete examples and data files from GitHub.
Aspose.HTML offers a free online EPUB to GIF Converter that converts EPUB to GIF image with high quality, easy and fast. Just upload, convert your files and get results in a few seconds!