Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert EPUB to GIF in C#, open the EPUB file as a stream, create
ImageSaveOptions with ImageFormat.Gif, and call
Converter.ConvertEPUB() with the stream, options, and output path.
GIF is a simple raster image format often used for lightweight web graphics and compatibility-focused image workflows. EPUB to GIF conversion is useful when a C# application needs to render eBook content into a broadly supported image format, while still controlling page setup, resolution, background color, and rendering quality.
Before running the examples, install and configure Aspose.HTML for .NET in your project. The complete C# example project is available in the Aspose.HTML for .NET GitHub repository.
A typical file-based conversion uses a readable EPUB file stream, an ImageSaveOptions object with ImageFormat.Gif, and Converter.ConvertEPUB(). The conversion writes a GIF image to the specified output path.
The workflow is:
File.OpenRead() or another readable stream.ImageSaveOptions instance and set the output format to ImageFormat.Gif. The default Format value is PNG, so the format must be set for GIF output.Converter.ConvertEPUB(stream, options, savePath) to write the GIF file.The following C# code converts an EPUB file to GIF.
1// Convert EPUB to GIF using C#
2
3// Open an existing EPUB file for reading
4using FileStream stream = File.OpenRead(DataDir + "input.epub");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "input-output.gif");
8
9// Create an instance of the ImageSaveOptions class
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif);
11
12// Call the ConvertEPUB() method to convert EPUB to GIF
13Converter.ConvertEPUB(stream, options, savePath);Use GIF output when compatibility with simple image viewers, legacy systems, or lightweight web graphics is more important than photographic quality. GIF is usually not the best choice for full-color EPUB pages, gradients, or high-detail previews. For sharper lossless page images, use EPUB to PNG. For smaller photographic previews, use EPUB to JPG.
For GIF output, create ImageSaveOptions(ImageFormat.Gif) explicitly because the default ImageSaveOptions.Format value is PNG. You can then tune page setup, background color, resolution, antialiasing, and text rendering in the options object.
Use
ImageSaveOptions when the output GIF needs custom rendering settings. The options object is passed to ConvertEPUB() and controls how EPUB content is rendered to raster image output.
| Option | Use it to control |
|---|---|
Css | CSS processing behavior through CssOptions. |
Format | The output image format. The default value is PNG; use ImageFormat.Gif for GIF output. |
BackgroundColor | The color used to fill the image background. The default value is transparent. |
PageSetup | Page size, margins, and page layout settings. |
HorizontalResolution and VerticalResolution | Output resolution values used by the rendering process. The default value is 300 dpi for each property. |
UseAntialiasing | Image rendering quality. Antialiasing is enabled by default. |
Text | Text rendering configuration through TextOptions. |
The following example creates a GIF file with custom ImageSaveOptions.
1// Convert EPUB to GIF in C# with custom settings
2
3// Open an existing EPUB file for reading
4using FileStream stream = File.OpenRead(DataDir + "input.epub");
5
6// Prepare a path for converted file saving
7string savePath = Path.Combine(OutputDir, "input-options.gif");
8
9// Initialize ImageSaveOptions
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif)
11{
12 UseAntialiasing = true,
13 HorizontalResolution = 400,
14 VerticalResolution = 400,
15 BackgroundColor = System.Drawing.Color.AliceBlue
16};
17options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(800, 500), new Margin(30, 20, 10, 10));
18
19// Call the ConvertEPUB() method to convert EPUB to GIF
20Converter.ConvertEPUB(stream, options, savePath);In this example, ImageSaveOptions is passed to Converter.ConvertEPUB() together with the EPUB stream and output path. The sample configures background color, page setup, rendering resolution, and antialiasing for the generated GIF image.
Use the online EPUB to GIF Converter for quick manual conversion. Use Aspose.HTML for .NET when EPUB to GIF conversion must run inside a C# application, service, or document pipeline.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.