HTML is a good presentation type for information in web browser. It can includes a variety of information and abundant interactive effect. But it might not be suitable for presentation in some situations. For instance, it is not applicable or convenient when you want to do a PowerPoint presentation and need to put a web page in it.

Then, you need to do something like converting HTML to another file format. Generally, you can convert it to PDF, Excel, Word or other file types. But for presentation like PowerPoint, an image file format will be more suitable. Considering converting HTML to an image format, then what image type is available? JPG, PNG, BMP may comes to your mind. Among them, JPG is often used for web graphics and many photos because this raster image format is easier to be transferred on the internet.

To convert HTML to image in C# programming, you just need an mature HTML converter like XsHtml .NET HTML to PDF SDK. This converter does not depend on web browsers, printer, and any other third party libraries. You can directly download our free trial online and integrate its library dll in your C# programming project.


C# HTML to Image Conversion Example

Please see a simple example for HTML to image conversion. Our HTML converter allows you to choose the output image file format from JPG, PNG, and BMP. And the following C# code only takes JPG image as an example.

string html = @"sample.html";

// Only support Jpeg/Jpg, Png and Bmp format
string savePath = "sample.jpg";

// Create a Html converter instance 
HtmlToImageConverter converter = new HtmlToImageConverter();

// Set output image size
converter.ImageHeight = 500;
converter.ImageWidth = 800;

// Convert html to image
converter.ConvertFromFile(html, savePath);

Notice - If you use the free trial version of .NET HTML to PDF SDK, the image quality is 50% of its original.