Scalable Vector Graphics (SVG) images are popular for their scalability. They are frequently used over the web for displaying visual information. In this article, you will learn how to create an SVG image file programmatically using C#. The following sections cover different use cases:
- C# SVG Image Creator – API Installation
- Create SVG Image File Programmatically with C#
- Create SVG Image with Embedded HTML Programmatically using C#
C# SVG Image Creator – API Installation
Aspose.SVG for .NET API can be used to create, edit, and manipulate SVG image files. You can iterate different nodes or convert the file to supported file formats. Please download the DLL files from the New Releases section, or use the following NuGet installation commands:
PM> Install-Package Aspose.SVG
After configuring the API successfully, you can learn how to create a simple and basic SVG image and later you will explore further with the help of an advanced example.
Create SVG Image File Programmatically with C#
- You can create an SVG image file with the following steps:
- Specify SVG content as a string.
- Initialize an object of SVGDocument class from the string content.
- Save the document to a file with the Save method.
The following code explains how to create an SVG image file programmatically using C#:
Create SVG Image with Embedded HTML Programmatically using C#
SVG is consistent with all XML-based languages for describing and rendering of embedded content. You can use element to include HTML content in an SVG file. Please follow the following steps to create SVG image with embedded HTML:
- Specify SVG content with embedded HTML.
- Specify the XHTML namespace from which the foreign object originates.
- Initialize an SVG document using SVGDocument.
- Save the document to a file with SVGSaveFormat enumeration.
The code below explains how to create an SVG image with embedded HTML content programmatically using C#:
Get Free API License
You can evaluate Aspose APIs without any limitations by requesting a Free Temporary License.
In this article, you have learned how to create SVG image files from scratch programmatically using C#. You have explored creating a simple SVG image as well as an advanced SVG image with embedded HTML content. You can further explore the API by taking a look at API Documentation. Moreover, in case of any queries, please feel free to contact us at the Free Support Forum.