Articles in this section
Category / Section

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

2 mins read

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

Steps to convert HTML to SVG 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 SVG.

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 SVG
htmlConverter.ConvertToSvg("http://www.google.com", "sample.svg");
//This will open the SVG file so, the result will be seen in default SVG viewer
Process.Start("Sample.svg");

 

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 SVG
htmlConverter.ConvertToSvg("http://www.syncfusion.com", "sample.svg")
'This will open the SVG file so, the result will be seen in default SVG viewer
Process.Start("Sample.svg")

 

You can download the work sample from HTMLToSVGSample.zip

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

Take a moment to peruse the documentation, where you will find other options like partial webpage to SVG 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.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied