Class SvgDocument
- Namespace
- Svg
- Assembly
- Svg.dll
The class used to create and load SVG documents.
public class SvgDocument : SvgFragment, ISvgTransformable, ICloneable, ISvgNode, ISvgViewPort, ISvgBoundable, ITypeDescriptorContext, IServiceProvider
- Inheritance
-
SvgDocument
- Implements
- Inherited Members
- Extension Methods
Constructors
SvgDocument()
Initializes a new instance of the SvgDocument class.
public SvgDocument()
Properties
BaseUri
public Uri BaseUri { get; set; }
Property Value
DisableDtdProcessing
Skip the Dtd Processing for faster loading of svgs that have a DTD specified. For Example Adobe Illustrator svgs.
public static bool DisableDtdProcessing { get; set; }
Property Value
ExternalCSSHref
Gets or sets an external Cascading Style Sheet (CSS)
public string ExternalCSSHref { get; set; }
Property Value
IdManager
Gets an SvgElementIdManager for this document.
protected virtual SvgElementIdManager IdManager { get; }
Property Value
Overflow
public override SvgOverflow Overflow { get; }
Property Value
PointsPerInch
public static int PointsPerInch { get; set; }
Property Value
Ppi
Gets or sets the Pixels Per Inch of the rendered image.
public int Ppi { get; set; }
Property Value
ResolveExternalElements
Which types of external elements, for example text definitions, are allowed to be resolved. Defaults to Local and Remote.
public static ExternalType ResolveExternalElements { get; set; }
Property Value
ResolveExternalImages
public static ExternalType ResolveExternalImages { get; set; }
Property Value
ResolveExternalXmlEntites
Which types of XML external entities are allowed to be resolved. Defaults to None to prevent XXE.
public static ExternalType ResolveExternalXmlEntites { get; set; }
Property Value
SkipGdiPlusCapabilityCheck
Skip check whether the GDI+ can be loaded.
public static bool SkipGdiPlusCapabilityCheck { get; set; }
Property Value
Remarks
Set to true on systems that do not support GDI+ like UWP.
X
Gets or sets the position where the left point of the svg should start.
public override SvgUnit X { get; }
Property Value
Y
Gets or sets the position where the top point of the svg should start.
public override SvgUnit Y { get; }
Property Value
Methods
Draw()
Renders the SvgDocument and returns the image as a Bitmap.
public virtual Bitmap Draw()
Returns
Draw(ISvgRenderer)
Renders the SvgDocument to the specified ISvgRenderer.
public void Draw(ISvgRenderer renderer)
Parameters
renderer
ISvgRendererThe ISvgRenderer to render the document with.
Exceptions
- ArgumentNullException
The
renderer
parameter cannot benull
.
Draw(Bitmap)
Renders the SvgDocument into a given Bitmap Bitmap.
public virtual void Draw(Bitmap bitmap)
Parameters
bitmap
Bitmap
Draw(Graphics)
Renders the SvgDocument to the specified Graphics.
public void Draw(Graphics graphics)
Parameters
Exceptions
- ArgumentNullException
The
graphics
parameter cannot benull
.
Draw(Graphics, SizeF?)
Renders the SvgDocument to the specified Graphics.
public void Draw(Graphics graphics, SizeF? size)
Parameters
graphics
GraphicsThe Graphics to be rendered to.
size
SizeF?The SizeF to render the document. If
null
document is rendered at the default document size.
Exceptions
- ArgumentNullException
The
graphics
parameter cannot benull
.
Draw(int, int)
Renders the SvgDocument in given size and returns the image as a Bitmap. If one of rasterWidth and rasterHeight is zero, the image is scaled preserving aspect ratio, otherwise the aspect ratio is ignored.
public virtual Bitmap Draw(int rasterWidth, int rasterHeight)
Parameters
Returns
EnsureSystemIsGdiPlusCapable()
Ensure that the running system is GDI capable, if not this will yield a SvgGdiPlusCannotBeLoadedException exception.
public static void EnsureSystemIsGdiPlusCapable()
FromSvg<T>(string)
Attempts to create an SVG document from the specified string data.
public static T FromSvg<T>(string svg) where T : SvgDocument, new()
Parameters
svg
stringThe SVG data.
Returns
- T
Type Parameters
T
GetElementById(string)
Retrieves the SvgElement with the specified ID.
public virtual SvgElement GetElementById(string id)
Parameters
Returns
- SvgElement
An SvgElement of one exists with the specified ID; otherwise false.
GetElementById<TSvgElement>(string)
Retrieves the SvgElement with the specified ID.
public virtual TSvgElement GetElementById<TSvgElement>(string id) where TSvgElement : SvgElement
Parameters
Returns
- TSvgElement
An SvgElement of one exists with the specified ID; otherwise false.
Type Parameters
TSvgElement
Open(string)
Opens the document at the specified path and loads the SVG contents.
public static SvgDocument Open(string path)
Parameters
Returns
- SvgDocument
An SvgDocument with the contents loaded.
Exceptions
- FileNotFoundException
The document at the specified
path
cannot be found.
Open(XmlDocument)
Opens an SVG document from the specified XmlDocument.
public static SvgDocument Open(XmlDocument document)
Parameters
document
XmlDocumentThe XmlDocument containing the SVG document XML.
Returns
Exceptions
- ArgumentNullException
The
document
parameter cannot benull
.
OpenAsBitmap(string)
public static Bitmap OpenAsBitmap(string path)
Parameters
path
string
Returns
OpenAsBitmap(XmlDocument)
public static Bitmap OpenAsBitmap(XmlDocument document)
Parameters
document
XmlDocument
Returns
Open<T>(Stream)
Attempts to open an SVG document from the specified Stream.
public static T Open<T>(Stream stream) where T : SvgDocument, new()
Parameters
Returns
- T
Type Parameters
T
Open<T>(Stream, SvgOptions)
Opens an SVG document from the specified Stream and adds the specified entities.
public static T Open<T>(Stream stream, SvgOptions svgOptions) where T : SvgDocument, new()
Parameters
stream
StreamThe Stream containing the SVG document to open.
svgOptions
SvgOptionsCss Style that will be applied to the Svg Document
Returns
- T
Type Parameters
T
Exceptions
- ArgumentNullException
The
stream
parameter cannot benull
.
Open<T>(Stream, Dictionary<string, string>)
Opens an SVG document from the specified Stream and adds the specified entities.
[Obsolete("Use Open<T>(Stream stream, SvgOptions svgOptions)")]
public static T Open<T>(Stream stream, Dictionary<string, string> entities) where T : SvgDocument, new()
Parameters
stream
StreamThe Stream containing the SVG document to open.
entities
Dictionary<string, string>Custom entity definitions.
Returns
- T
Type Parameters
T
Exceptions
- ArgumentNullException
The
stream
parameter cannot benull
.
Open<T>(string)
Opens the document at the specified path and loads the SVG contents.
public static T Open<T>(string path) where T : SvgDocument, new()
Parameters
Returns
- T
An SvgDocument with the contents loaded.
Type Parameters
T
Exceptions
- FileNotFoundException
The document at the specified
path
cannot be found.
Open<T>(string, SvgOptions)
Opens the document at the specified path and loads the SVG contents.
public static T Open<T>(string path, SvgOptions svgOptions) where T : SvgDocument, new()
Parameters
path
stringA string containing the path of the file to open.
svgOptions
SvgOptionsA dictionary of custom entity definitions to be used when resolving XML entities within the document.
Returns
- T
A SvgDocument with the contents loaded.
Type Parameters
T
Exceptions
- FileNotFoundException
The document at the specified
path
cannot be found.
Open<T>(string, Dictionary<string, string>)
Opens the document at the specified path and loads the SVG contents.
[Obsolete("Use Open<T>(string path, SvgOptions svgOptions)")]
public static T Open<T>(string path, Dictionary<string, string> entities) where T : SvgDocument, new()
Parameters
path
stringA string containing the path of the file to open.
entities
Dictionary<string, string>A dictionary of custom entity definitions to be used when resolving XML entities within the document.
Returns
- T
An SvgDocument with the contents loaded.
Type Parameters
T
Exceptions
- FileNotFoundException
The document at the specified
path
cannot be found.
Open<T>(XmlReader)
Attempts to open an SVG document from the specified XmlReader.
public static T Open<T>(XmlReader reader) where T : SvgDocument, new()
Parameters
Returns
- T
Type Parameters
T
OverwriteIdManager(SvgElementIdManager)
Overwrites the current IdManager with a custom implementation. Be careful with this: If elements have been inserted into the document before, you have to take care that the new IdManager also knows of them.
public void OverwriteIdManager(SvgElementIdManager manager)
Parameters
manager
SvgElementIdManager
RasterizeDimensions(ref SizeF, int, int)
If both or one of raster height and width is not given (0), calculate that missing value from original SVG size while keeping original SVG size ratio
public virtual void RasterizeDimensions(ref SizeF size, int rasterWidth, int rasterHeight)
Parameters
SystemIsGdiPlusCapable()
Validate whether the system has GDI+ capabilities (non Windows related).
public static bool SystemIsGdiPlusCapable()
Returns
- bool
Boolean whether the system is capable of using GDI+
Write(Stream, bool)
public void Write(Stream stream, bool useBom = true)
Parameters
Write(string, bool)
public void Write(string path, bool useBom = true)
Parameters
Write(XmlWriter)
Write this SvgElement out using a given XmlWriter.
public override void Write(XmlWriter writer)
Parameters
writer
XmlWriterThe XmlWriter to use.
Remarks
Recommendation is to create an XmlWriter by calling a factory method,
e.g. Create(Stream),
as per Microsoft documentation.
However, unlike an XmlTextWriter created via 'new XmlTextWriter()',
a factory-constructed XmlWriter will not flush output until it is closed
(normally via a using statement), or unless the client explicitly calls Flush().
WriteAttributes(XmlWriter)
protected override void WriteAttributes(XmlWriter writer)
Parameters
writer
XmlWriter