We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Close Icon
Unfortunately, activation email could not send to your email. Please try again.
Close Icon
close icon
Vote for your favorite ebook
Succinctly Readers Awards 2020
Syncfusion Feedback

How to convert HTML to image using C# and VB.NET

Platform: WinForms |
Control: PDF |
Published Date: October 26, 2018 |
Last Revised Date: May 2, 2019

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can convert HTML to image in C# and VB.NET by using the advanced WebKit rendering engine.

Steps to convert HTML to image programmatically:

  1. Create a new C# console application project. creation of console application project
  2. Install the Syncfusion.HtmlToPdfConverter.QtWebKit.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. NuGet package reference
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.HtmlConverter;

 

VB.NET

Imports Syncfusion.HtmlConverter

 

  1. Use the following code snippet to convert HTML to image.

C#

//Initialize HTML converter with WebKit rendering engine
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings webKitSettings = new WebKitConverterSettings();
//Set WebKit path
webKitSettings.WebKitPath = @"/QtBinaries/";
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = webKitSettings;
//Convert URL to Image
Image[] image = htmlConverter.ConvertToImage("http://www.google.com");
//Save the image
image[0].Save("Sample.jpg");
//This will open the image file so, the result will be seen in default image viewer
Process.Start("Sample.jpg");

 

VB.NET

'Initialize HTML converter with WebKit rendering engine
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
Dim webKitSettings As New WebKitConverterSettings()
'Set WebKit path
webKitSettings.WebKitPath = "/QtBinaries/"
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = webKitSettings
'Convert URL to Image
Dim image As Image() = htmlConverter.ConvertToImage("http://www.google.com")
'Save the image
image(0).Save("Sample.jpg")
'This will open the image file so, the result will be seen in default image viewer
Process.Start("Sample.jpg")

 

You can download the work sample from HTMLToImageSample.zip

By executing the program, you will get the image output as follows. Output image file

Take a moment to peruse the documentation, where you will find other options like HTML string to image and partial webpage to image, with code examples.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Chad Carey
Aug 14, 2019

can you explain the WebKitPath part? I have your entire thing installed and licensed but no idea where this is.

Reply
Gowthamraj Kumar [Syncfusion]
Aug 19, 2019

Hi Chad,

Our HTML converter internally make use of QtWebKit rendering engine for converting HTML to PDF. So, the converter required QtBinaries to perform the conversion. We need to set the path of the QtBinaries folder to WebKitPath property in WebKitConverterSettings. The QtBinaries folder is available in HTML converter installer and HTML to PDF converter NuGet packages.

Please refer below link to download the HTML converter installer. The samples, QtBinaries, assemblies will be available in the HTML converter installed location.

Steps to download the HTML Converter Installer

Prerequisites for Windows

The required files can be get from the HTML to PDF converter NuGet packages. Please refer below link for more information,

KB : How to install WebKit HTML converter using NuGet package manager

Please let us know if you need any further assistance on this.

Regards,

Gowthamraj K

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon