You can read all the details at: Create SVG Image File Programmatically using C#
Last active
December 23, 2021 06:23
-
-
Save aspose-com-gists/43e53ea52673b2211d6023a13b3a3dde to your computer and use it in GitHub Desktop.
Create SVG Image File Programmatically using C# | Embedded HTML Contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specify SVG content with embedded HTML. | |
// Specify the XHTML namespace from which the foreign object originates. | |
string documentContent = "<svg viewBox =\"0 0 200 200\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n div {\n color: white;\n font: 18px serif;\n height: 100%;\n overflow: hidden;\n }\n </style>\n \n <polygon points=\"5,5 195,10 185,185 10,195\" />\n\n <!-- Common use case: embed HTML text into SVG -->\n <foreignObject x=\"20\" y=\"20\" width=\"160\" height=\"160\">\n <!--\n In the context of SVG embedded in an HTML document, the XHTML \n namespace could be omitted, but it is mandatory in the \n context of an SVG document\n -->\n <div xmlns=\"http://www.w3.org/1999/xhtml\">\n Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n Sed mollis mollis mi ut ultricies. Nullam magna ipsum,\n porta vel dui convallis</div>\n </foreignObject>\n</svg>"; | |
// Initialize an SVG document using SVGDocument. | |
SVGDocument document = new SVGDocument(documentContent, "."); | |
// Save the document to a file with SVGSaveFormat enumeration. | |
document.Save(dataDir + "Test.svg", SVGSaveFormat.SVG); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specify SVG content as string | |
string documentContent = "<svg xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"50\" cy=\"50\" r=\"40\" /></svg>"; | |
// Initialize an object of SVGDocument class from the string content | |
SVGDocument document = new SVGDocument(documentContent, "."); | |
// Save the document to a file | |
document.Save(dataDir + "test.svg", SVGSaveFormat.SVG); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment