Last active
February 23, 2021 09:11
-
-
Save aspose-com-gists/32cf16c0f8fd21b90ab8f787c6af0395 to your computer and use it in GitHub Desktop.
Inspect, Extract, or Navigate SVG Image Elements Programmatically using C#
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
//Load a document from a file | |
string documentPath = Path.Combine(DataDir, "shapes.svg"); | |
using (var document = new SVGDocument(documentPath)) | |
{ | |
// Get the root svg element of the document | |
var svg = document.DocumentElement; | |
// Find the first child element with a given tag name | |
var g = svg.GetElementsByTagName("g").First() as SVGGElement; | |
var rect = g.FirstElementChild as SVGRectElement; | |
Console.WriteLine("Height: {0}", rect.Height);// 90 | |
Console.WriteLine("Width: {0}", rect.Width); // 100 | |
} |
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
// Load a document | |
string documentPath = Path.Combine(DataDir, "shapes.svg"); | |
using (var document = new SVGDocument(documentPath)) | |
{ | |
var element = document.DocumentElement; | |
Console.WriteLine(element.TagName); // svg | |
element = element.LastElementChild; | |
Console.WriteLine(element.TagName); // g | |
element = element.FirstElementChild; | |
Console.WriteLine(element.TagName); // rect | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment