This Gist contains practical C# examples from the Aspose.SVG for .NET documentation demonstrating how to work with SVG text, fonts, and styles using Aspose.SVG for .NET. The examples focus on real-world scenarios where SVG text rendering behaves differently across browsers, image formats, and PDF output – and how to control that behavior programmatically.
The code samples are grouped around two core topics:
Examples show how to:
- Create and style
<text>elements programmatically. - Render SVG text using custom fonts.
- Configure font lookup folders for consistent rendering.
- Apply font fallback for image and PDF conversions.
- Embed fonts using
@font-face(inline and programmatically). - Modify font-family of existing SVG text elements.
- Ensure consistent text rendering across PNG, JPEG, and PDF outputs.
These scenarios are essential when:
- system fonts are unavailable on the server
- SVG looks correct in the browser but breaks during conversion
- text layout changes between output formats
Examples demonstrate how to:
- Apply global CSS styles to SVG text elements.
- Remove or clean up conflicting inline styles.
- Move presentation logic from inline attributes to
<style>blocks. - Control CSS precedence for predictable rendering results.
- Use DOM manipulation to normalize and enforce text styling.
These techniques help avoid common issues such as:
- ignored CSS rules
- unexpected inline overrides
- inconsistent appearance after export
- Ensure you have the Aspose.SVG for .NET library installed via NuGet.
- Clone or download this gist repository.
- Open any example in your preferred .NET IDE (Visual Studio, Rider, etc.).
- Adjust file paths, input, and output parameters as needed.
- Run the code to see the feature in action.
- .NET Framework 4.6.1+, .NET Core 2.0+, or .NET 5+.
- Supported OS: Windows, Linux, macOS.
- Visual Studio (or any .NET‑compatible IDE).
- Aspose.SVG for .NET installed via NuGet.
Aspose.SVG for .NET is a powerful, on‑premise library designed to create, parse, manipulate, and convert SVG files. It provides a rich API for working with SVG DOM, applying styles, embedding fonts, and rendering to various output formats such as PNG, JPEG, PDF, and XPS.