Extract SVG from Website in C#

Have you ever been in a situation where you wanted to save or download SVG images from a web page or from a live URL? Scalable Vector Graphics (SVG) is a popular image format used on webpages. SVG images are vector-based, which means that they are made up of mathematical objects that can be scaled to any size without losing quality. This makes them a versatile and efficient format for storing and displaying images. In this blog post, we will discuss how to extract SVG from a website in C#.

This article covers the following topics:

  1. C# API to Extract SVG from Website
  2. Extract SVG from Website
  3. Download External SVG Images from website
  4. Free Learning Resources

C# API to Extract SVG from Website

We will use the Aspose.HTML for .NET for extracting SVG from websites. It allows developers to manipulate and process HTML documents. It can be used to automate the manipulation, conversion, or analysis of HTML documents within a .NET application. Developers can save time and effort by implementing a ready-to-use solution for handling HTML-related tasks programmatically. It also allows the conversion of HTML web pages and documents to supported formats without any external software.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Html

Extract SVG from Website in C#

We can extract all the SVG images that are embedded using the <svg> element by following the steps below:

  1. Load a webpage using the HTMLDocument class.
  2. Read all inline SVG images using the GetElementsByTagName() method.
  3. Finally, loop through all the images and save to a local file system.

The following code sample shows how to extract SVG from a website in C#.

Extract SVG from Website in C#

Extract SVG from Website in C#

Download External SVG Images from Website in C#

We can extract all the SVG images that are stored outside an HTML document and loaded into the document by following the steps below:

  1. Load a webpage using the HTMLDocument class.
  2. Read all inline SVG images using the GetElementsByTagName() method.
  3. Finally, loop through all the images and save to a local file system.

The following code sample shows how to extract externally embedded SVG from a website in C#.

Get Free License

You can get a free temporary license to try Aspose.HTML for .NET without evaluation limitations.

Extract SVG from Website – Learning Resources

You can learn more about extracting SVG from websites and explore various other features of the library using the resources below:

Conclusion

In this article, we learned how to extract SVG from websites in C#. The ability to extract SVGs from websites or webpages brings a new dimension to digital creativity. Whether it’s for archiving inspiring graphics, analyzing design trends, or enhancing your own projects, the steps outlined in this article show how the process is relatively simple and requires a few lines of code. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also