convert SVG to HTML

Scalable Vector Graphic, SVG, files are commonly used over the web because of their scalability without changing the quality of the image. Two-dimensional graphics like logos, icons, and illustrations are often rendered in SVG file format. You can easily convert SVG to HTML file programmatically using C# language. In this article, you will learn several details about SVG to HTML webpage conversion:

SVG to HTML Converter - C# API Installation

Aspose.SVG for .NET API lets you create, edit, or convert SVG files programmatically in your .NET applications. You can render SVG to PDF format and then utilize Aspose.PDF for .NET API for converting the PDF to HTML format file. You can easily configure these APIs by Downloading the DLL files from the New Releases section, or with the following NuGet commands:

PM> Install-Package Aspose.SVG
PM> Install-Package Aspose.Pdf

Steps to Convert SVG to HTML Webpage Programmatically in C#

Please follow the steps below for converting SVG to HTML file using C#:

// Initialize MemoryStream to save intermediary PDF file
MemoryStream stream = new MemoryStream();
// Load input SVG file
using (SVGDocument document = new SVGDocument("Sample.svg"))
// Specify PdfRenderingOptions
PdfRenderingOptions options = new PdfRenderingOptions()
{
// Set Page Setup properties
PageSetup =
{
Sizing = SizingType.FitContent
}
};
  • Initialize PdfDevice class instance for exporting PDF file.
// Initialize PdfDevice class object
using (PdfDevice device = new PdfDevice(options, stream))
{
// Render SVG to PDF file
document.RenderTo(device);
}
view raw PdfDevice.cs hosted with ❤ by GitHub
  • Load the PDF file from MemoryStream object and convert it to HTML file with SaveFormat enumeration.
// Load the rendered PDF document
Document pdfDocument = new Document(stream);
// Save SVG file contents to output HTML format
pdfDocument.Save("Sample.html", SaveFormat.Html);
view raw PDFtoHTML.cs hosted with ❤ by GitHub

C# Convert SVG to HTML – Complete Code Snippet

The following code sample shows how to convert SVG to HTML webpage programmatically using C#:

// Initialize MemoryStream to save intermediary PDF file
MemoryStream stream = new MemoryStream();
// Load input SVG file
using (SVGDocument document = new SVGDocument("Sample.svg"))
{
// Specify PdfRenderingOptions
PdfRenderingOptions options = new PdfRenderingOptions()
{
// Set Page Setup properties
PageSetup =
{
Sizing = SizingType.FitContent
}
};
using (PdfDevice device = new PdfDevice(options, stream))
{
// Render SVG to PDF file
document.RenderTo(device);
}
}
// Load the PDF document
Document pdfDocument = new Document(stream);
// Save SVG file contents to output HTML format
pdfDocument.Save("Sample.html", SaveFormat.Html);

Get Free License

You can try different features offered by Aspose APIs by requesting for a Free Temporary License.

Conclusion

In this article, you have learned how to convert SVG to HTML webpage file format programmatically using C#. You can further explore the Documentation of Aspose.SVG for .NET and Aspose.PDF for .NET API to check out different features. In case of any concerns, please feel to write to us at the Free Support Forum.

See Also