Aspose.SVG
25.6.0
dotnet add package Aspose.SVG --version 25.6.0
NuGet\Install-Package Aspose.SVG -Version 25.6.0
<PackageReference Include="Aspose.SVG" Version="25.6.0" />
<PackageVersion Include="Aspose.SVG" Version="25.6.0" />
<PackageReference Include="Aspose.SVG" />
paket add Aspose.SVG --version 25.6.0
#r "nuget: Aspose.SVG, 25.6.0"
#:package Aspose.SVG@25.6.0
#addin nuget:?package=Aspose.SVG&version=25.6.0
#tool nuget:?package=Aspose.SVG&version=25.6.0
Create, Modify, & Convert SVG via .NET API
Aspose.SVG for .NET is a powerful library designed to work with SVG documents in .NET applications. It allows developers to create, manipulate, and convert SVG files into various formats like PDF, SVGZ, PNG, JPG, TIFF, and more. The library supports SVG vectorization, custom configuration, document merging, transformations, and advanced features like gradients, filters, and path building. Perfect for developers aiming to enhance graphical content and automate SVG workflows in .NET environments.
SVG Document Creation and Loading
- Create an Empty SVG Document: Use the
SVGDocument()
constructor to create a blank SVG document. - Create SVG from Memory String: Create an SVG file from a memory string using
SVGDocument()
constructors. - Create SVG from a Stream: Load SVG from different streams like memory or file using overloaded
SVGDocument()
constructors. - Create Custom SVG with Builder API: Use
SVG Builder
API to programmatically construct and customize SVG documents in a streamlined manner. - Load SVG or SVGZ from File or URL: Load existing SVG and SVGZ files using
SVGDocument
class. - Read SVG with Resources Async: Asynchronously load SVG with external resources using the
OnReadyStateChange
event handler.
SVG Document Editing and Modification
- Add Elements to SVG: Insert new SVG elements using
CreateElementNS()
method andInsertBefore()
to append nodes. - Add Basic Shapes to SVG: Add geometric shapes like circles and rectangles.
- Edit Existing Elements: Modify elements in the DOM using
SetAttribute()
,GetAttribute()
, and other methods. - SVG Drawing on Bitmap: Draw and modify an SVG directly on a bitmap image using the rendering engine.
- Edit SVG Path: Update and customize path elements using the path API.
SVG Document Navigation and Inspection
- Navigation using DOM: Traverse and inspect SVG elements using DOM methods like
DocumentElement
,GetElementsByTagName()
, and more. - Inspect Specific Elements: Extract detailed information about individual elements within an SVG using DOM properties.
- Use CSS Selector for Editing: Modify and style SVG elements using CSS Selectors within the API.
- XPath Query Navigation: Use XPath queries to navigate through nodes in the SVG document.
SVG Conversion and Rendering
- Convert SVG to PDF: Use the
ConvertSVG()
method to export SVG to PDF. - Convert SVG to XPS: Use
ConvertSVG()
method to convert SVG into XPS format. - Convert SVG to SVGZ and vice versa: Use the
SVGSaveFormat
enumeration of Aspose.Svg.Saving namespace specifies the format in which the document is saved, and you can select an SVG or SVGZ format. - Convert SVG to Image Formats: Export SVG documents to image formats like PNG, JPG, BMP, TIFF, and GIF.
- Rendering Options: Set rendering options such as background color, resolution, protection, and page size using
ImageRenderingOptions
,PdfRenderingOptions
, andXpsRenderingOptions
.
Image Vectorization and SVG Optimization
- Image Vectorization: Convert raster images like PNG, JPG, GIF, TIFF, ICO, and BMP into scalable vector graphics using the
ImageVectorizer
class. - Image Stencil: Create stenciling effects from images using the process of image vectorization.
- Text Vectorization: Convert text within SVG into vectorized paths to protect against modifications and ensure high-quality rendering.
- SVG Optimization: Reduce the file size and clean up the SVG by removing unnecessary elements and attributes.
Environment Configuration
- Custom Configuration: Create and apply custom configuration settings for runtime services, web requests, and more.
- Logging and Message Handlers: Set up logging of network requests and errors using
LogMessageHandler
.
Advanced SVG Features
- Merge Multiple SVGs: Combine multiple SVG documents into a single file using the
Render()
method. - Apply SVG Transformations: Perform transformations like rotation, scaling, and skewing on SVG elements.
- SVG Filters: Apply SVG filters like Gaussian blur, drop shadow, and color saturation through code.
- SVG Gradients: Create and apply gradients (linear, radial) within SVG files.
- SVG Text and Fonts: Manipulate text using SVG-specific tags like
<text>
,<tspan>
, and apply glyphs and fonts.
SVG Builder API
- SVGElementBuilder: Create new SVG elements through a fluent API.
- Path Builder: Customize SVG paths programmatically for accurate rendering.
- Paint Builder: Apply stroke and fill attributes to SVG elements efficiently.
Supported File Formats
Format | Description | Load | Save |
---|---|---|---|
SVG | Scalable Vector Graphics Format | ✔️ | ✔️ |
SVGZ | Compressed version of SVG | ✔️ | ✔️ |
Portable Document Format | ✔️ | ||
XPS | XML Paper Specification | ✔️ | |
TIFF | Tagged Image File Format | ✔️ | |
BMP | Bitmap Image File Format | ✔️ | |
PNG | Portable Network Graphics | ✔️ | |
JPEG | Joint Photographic Expert Group | ✔️ | |
GIF | Graphical Interchange Format | ✔️ |
System Requirements
To build and manipulate SVG documents, the machine running Aspose.SVG for .NET does not require modeling and rendering software installed. Aspose.SVG for .NET includes a document generation engine.
Category | Details |
---|---|
Supported Operating System | |
Windows | - Microsoft Windows Server 2022 (x64), - Microsoft Windows 2019 Server (x64), - Microsoft Windows 2016 Server (x64), - Microsoft Windows Server 2012 R2 (x64), - Microsoft Windows Server 2012 (x64), - Microsoft Windows Server 2008 R2 SP1 (x64), - Microsoft Windows Server 2008 SP2 (x64, x86), - Microsoft Windows 11 (x64), - Microsoft Windows 10 (x64, x86), - Microsoft Windows 8.1 (x64, x86), - Microsoft Windows 8 (x64, x86), - Microsoft Windows 7 SP1 (x64, x86), - Microsoft Azure |
macOS | - Mac OS X x64 (10.12+) |
Linux | - Linux x64 (6, 7, 27, 9, 8.7+, 18.04, 16.04, 14.04, 18, 17, 42.3+, 12 SP2+) |
Development Environments | - Microsoft Visual Studio 2010, - Microsoft Visual Studio 2011, - Microsoft Visual Studio 2012, - Microsoft Visual Studio 2013, - Microsoft Visual Studio 2015, - Microsoft Visual Studio 2017, - Microsoft Visual Studio 2019 |
Supported Frameworks | .NET Standard 2.0, Compatible with: - .NET Framework 4.6.1+, - .NET Standard 2.0/2.1, - .NET Core 2.0+, - .NET 5.0+ |
Steps to Install Aspose.SVG for .NET through NuGet
1. Open Visual Studio Project
- Open your solution or project in Visual Studio.
2. Install NuGet Package Manager (if needed)
- Go to
Tools
>Extension Manager
. - Search for "NuGet Package Manager" in the Online Gallery.
- Download and install it.
- Restart Visual Studio.
3. Install Aspose.SVG using Package Manager Console
- Open
Tools
>Library Package Manager
>Package Manager Console
. - Type
Install-Package Aspose.SVG
for the latest version orInstall-Package Aspose.SVG -prerelease
for the latest release with hotfixes. - Press Enter.
4. Update Aspose.SVG via Package Manager Console
- Open the
Package Manager Console
again. - Type
Update-Package Aspose.SVG
to update to the latest release, or use-prerelease
for hotfixes.
5. Install/Update Using GUI
- Go to
Tools
>Library Package Manager
>Manage NuGet Packages
or right-click the project name in Solution Explorer. - Search for
Aspose.SVG
in the online package search. - Click Install/Update next to the latest version of Aspose.SVG for .NET.
Create SVG from Scratch Using SVG Builder
Aspose.SVG SVG Builder API employs the Fluent Builder Pattern, a design methodology that aligns perfectly with the need for simplicity, clarity, and versatility in SVG manipulation. The following example is a concise and elegant approach to creating SVG from scratch:
// Create an <svg> element with specified width, height and viewBox, and add into it other required elements
SVGSVGElement svg = new SVGSVGElementBuilder()
.Width(700).Height(300)
.ViewBox(0, 0, 700, 300)
.AddG(g => g
.AddCircle(circle => circle.Cx(130).Cy(130).R(60).Fill(Paint.None).Stroke(Color.FromArgb(200, 0, 0)).StrokeWidth(70).StrokeDashArray(2, 14))
.AddText("I can create SVG from scratch!", x: 270, y: 140, fontSize: 30, fill: Color.Teal)
)
.Build(document.FirstChild as SVGSVGElement);
// Save the document
document.Save(Path.Combine(OutputDir, "svg-from-scratch.svg"));
Source – Element Builders – Create and Edit SVG Elements
Convert SVG to PNG
Quickly convert SVG files to PNG images using the Aspose.SVG for .NET library. A simple solution for rendering high-quality PNGs from SVG documents:
// Initialize an SVG document from a file
using (SVGDocument document = new SVGDocument("image.svg"))
{
// Initialize ImageSaveOptions
ImageSaveOptions saveOptions = new ImageSaveOptions();
// Convert SVG to PNG
Converter.ConvertSVG(document, saveOptions, "image.png");
}
Source – Convert SVG to Images
Merge Multiple SVG Documents into a Single PDF
Combine multiple SVG files into a single PDF with the Aspose.SVG for .NET API. The Render()
method allows you to send several documents at once to the output rendering device and merge them:
// Load multiple SVG documents from files
using (SVGDocument document1 = new SVGDocument(Path.Combine(DataDir, "circle.svg")))
using (SVGDocument document2 = new SVGDocument(Path.Combine(DataDir, "flower.svg")))
using (SVGDocument document3 = new SVGDocument(Path.Combine(DataDir, "lineto.svg")))
{
// Initialize the SvgRenderer for rendering multiple SVGs
using (SvgRenderer renderer = new SvgRenderer())
{
// Create a PdfDevice to save the output as a PDF
using (PdfDevice device = new PdfDevice(Path.Combine(OutputDir, "result.pdf")))
{
// Render and merge all SVG documents into a single PDF
renderer.Render(device, document1, document2, document3);
}
}
}
Source – How to Merge SVG Files
Rotate SVG Element Using SVG Builder
You can perform SVG transformations such as rotation, scaling, and translation on individual elements or the entire SVG document. The following C# code snippet demonstrates how to find the desired SVG element (the first <rect>
) in an existing SVG file and rotate it around its center.
// Load an SVG document
using (SVGDocument document = new SVGDocument(Path.Combine(DataDir, "shapes.svg")))
{
// Find the first <rect> element for rotation
SVGRectElement rect = document.GetElementsByTagName("rect").First() as SVGRectElement;
// Rotate the first <rect> element around its center using the SVGRectElementBuilder
new SVGRectElementBuilder()
.Transform(t => t.Rotate(45, 100, 140))
.Build(rect);
// Save the document
document.Save(Path.Combine(OutputDir, "rotate-element-using-builder.svg"));
}
Source – Rotate SVG
Vectorize Image – Convert Raster Image to Vector Graphic
Implement the image vectorization process and work with various pre-processing options for images before saving them in vector format:
// Initialize an instance of the ImageVectorizer class
ImageVectorizer vectorizer = new ImageVectorizer
{
// Optionally set configuration
Configuration =
{
// Optionally set path builder
PathBuilder = new BezierPathBuilder {
// Optionally set trace smoother
TraceSmoother = new ImageTraceSmoother(2),
},
ColorsLimit = 10,
LineWidth = 1
}
};
// Vectorize image from the specified file
using SVGDocument document = vectorizer.Vectorize("flower.png");
// Save the vectorized image as an SVG file
document.Save("flower.svg");
Source – Image Vectorization
Tags
SVG Creation | SVG Conversion | SVG Manipulation | Vector Graphics | Image Vectorization | Text Vectorization | SVG Optimization | SVG to PDF | SVG to PNG | Image Conversion | Rendering Options | Custom Configuration | CSS Selector | XPath Navigation | SVG Filters | SVG Gradients | SVG Transformations | Advanced SVG Features | SVG to XPS | Document Merging | SVG Builder API | High-Quality Rendering | Bitmap Rendering | Path Builder | PDF Export | SVG Document Navigation | Logging and Message Handlers | Image Formats
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- System.Diagnostics.DiagnosticSource (>= 7.0.0)
- System.Drawing.Common (>= 4.7.3)
- System.Numerics.Vectors (>= 4.5.0)
- System.Security.Permissions (>= 4.5.0)
- System.Text.Encoding.CodePages (>= 4.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Aspose.SVG:
Package | Downloads |
---|---|
Aspose.Total
Aspose.Total for .NET is the most complete package of all .NET file format APIs offered by Aspose. It empowers developers to create, edit, render, print and convert between a wide range of popular document formats within any .NET, C#, ASP.NET and VB.NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
25.6.0 | 1,942 | 6/20/2025 |
25.5.0 | 2,583 | 5/15/2025 |
25.4.0 | 3,908 | 4/11/2025 |
25.3.0 | 3,728 | 3/9/2025 |
25.2.0 | 3,692 | 2/18/2025 |
25.1.0 | 1,440 | 1/30/2025 |
24.12.0 | 10,181 | 12/18/2024 |
24.11.0 | 6,189 | 11/27/2024 |
24.10.0 | 15,777 | 10/30/2024 |
24.9.0 | 12,617 | 9/19/2024 |
24.8.0 | 4,735 | 8/22/2024 |
24.7.0 | 3,046 | 7/18/2024 |
24.6.0 | 6,688 | 6/17/2024 |
24.5.0 | 14,252 | 5/3/2024 |
24.4.0 | 5,728 | 4/5/2024 |
24.3.0 | 8,936 | 3/6/2024 |
24.2.0 | 6,459 | 2/10/2024 |
24.1.0 | 8,038 | 1/18/2024 |
23.12.0 | 9,233 | 12/16/2023 |
23.11.0 | 1,691 | 12/3/2023 |
23.10.0 | 32,725 | 10/25/2023 |
23.9.0 | 19,900 | 9/18/2023 |
23.8.1 | 110,421 | 8/12/2023 |
23.7.0 | 9,139 | 7/27/2023 |
23.6.0 | 11,585 | 6/29/2023 |
23.5.0 | 9,723 | 5/25/2023 |
23.4.0 | 46,564 | 4/19/2023 |
23.3.0 | 17,427 | 3/21/2023 |
23.2.0 | 9,453 | 2/28/2023 |
23.1.0 | 43,383 | 1/31/2023 |
22.12.0 | 2,878 | 1/17/2023 |
22.11.0 | 23,107 | 11/25/2022 |
22.10.0 | 7,575 | 10/31/2022 |
22.9.0 | 21,180 | 9/30/2022 |
22.8.0 | 22,921 | 8/30/2022 |
22.7.0 | 15,813 | 7/27/2022 |
22.6.0 | 20,895 | 6/21/2022 |
22.5.0 | 9,167 | 5/20/2022 |
22.4.0 | 11,775 | 4/21/2022 |
22.3.0 | 14,386 | 3/12/2022 |
22.2.0 | 14,450 | 2/17/2022 |
22.1.0 | 8,067 | 1/16/2022 |
21.12.0 | 8,965 | 12/3/2021 |
21.11.0 | 9,445 | 11/3/2021 |
21.10.0 | 7,765 | 10/12/2021 |
21.9.0 | 19,252 | 9/7/2021 |
21.8.0 | 12,618 | 8/5/2021 |
21.7.0 | 14,457 | 7/2/2021 |
21.6.0 | 3,813 | 6/3/2021 |
21.5.0 | 11,261 | 5/12/2021 |
21.4.0 | 20,427 | 4/9/2021 |
21.3.0 | 10,218 | 3/12/2021 |
21.2.0 | 10,725 | 2/10/2021 |
21.1.0 | 5,721 | 1/25/2021 |
20.12.0 | 4,729 | 12/14/2020 |
20.11.0 | 9,631 | 11/12/2020 |
20.10.0 | 3,215 | 10/29/2020 |
20.9.0 | 5,366 | 9/25/2020 |
20.8.0 | 4,506 | 8/21/2020 |
20.7.0 | 24,192 | 7/31/2020 |
20.6.0 | 3,557 | 6/30/2020 |
20.5.0 | 3,458 | 5/29/2020 |
20.4.0 | 10,817 | 4/28/2020 |
20.2.0 | 4,029 | 2/27/2020 |
20.1.0 | 3,268 | 1/30/2020 |