This quick guide covers the details to convert text to SVG using C#. It includes the step-by-step process and a runnable sample code to make SVG from text using C#. Moreover, you will also learn about customizing the output SVG file containing text as per your requirements.
Steps to Create SVG from Text using C#
- Set up the IDE to use Aspose.SVG for .NET to convert text to SVG image
- Create an instance of the SVGDocument class and access the root SVG element
- Define SVG Text element with the CreateElementNS method
- Specify the text contents and set different appearance attributes
- Append text to the root and render the output SVG image
These steps explain the process to create SVG text using C#. Commence the process by preparing the environment on your end as a prerequisite. Subsequently, specify the text string and different appearance parameters like the color and position coordinates before rendering the output vector image.
Code to Create Text SVG using C#
This sample code demonstrates the basic version to create SVG from text using C#. First, initiate the SVGDocument class object, and the root element is accessed using the RootElement property. Next, the SVG text element is defined and appended to the root using the AppendChild method before exporting the output SVG image. However, you can further enhance this code by setting the text path, text style, and TSpan to apply different appearances to the text in the SVG image.
This article has taught us to create text SVG using C#. Besides, if you want to change the background color of an SVG, then read the article on how to change background color of SVG in C#.