Create SVG Image File Programmatically using C#

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

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#

  1. You can create an SVG image file with the following steps:
  2. Specify SVG content as a string.
  3. Initialize an object of SVGDocument class from the string content.
  4. 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 <foreignObject> element to include HTML content in an SVG file. Please follow the following steps to create SVG image with embedded HTML:

  1. Specify SVG content with embedded HTML.
  2. Specify the XHTML namespace from which the foreign object originates.
  3. Initialize an SVG document using SVGDocument.
  4. 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.

Conclusion

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.

See Also

Convert SVG to PDF or XPS Programmatically using C# VB.NET