Class SvgConverter
This is the main container class for static methods that do high-level conversion operations from input to PDF, either by drawing on a canvas or by returning an XObject, which can then be used by the calling class for further processing and drawing operations.
public sealed class SvgConverter
- Inheritance
-
SvgConverter
- Inherited Members
Methods
ConvertToImage(Stream, PdfDocument)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument.
public static Image ConvertToImage(Stream stream, PdfDocument document)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
Returns
Remarks
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToImage(Stream, PdfDocument, ISvgConverterProperties)
Converts a String containing valid SVG content to an image that can then be used on the passed PdfDocument.
public static Image ConvertToImage(Stream stream, PdfDocument document, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
Remarks
Converts a String containing valid SVG content to an image that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToXObject(Stream, PdfDocument)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument.
public static PdfFormXObject ConvertToXObject(Stream stream, PdfDocument document)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
Returns
- PdfFormXObject
a XObject containing the PDF instructions corresponding to the passed SVG content
Remarks
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToXObject(Stream, PdfDocument, ISvgConverterProperties)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument.
public static PdfFormXObject ConvertToXObject(Stream stream, PdfDocument document, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
- PdfFormXObject
a XObject containing the PDF instructions corresponding to the passed SVG content
Remarks
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToXObject(string, PdfDocument)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument.
public static PdfFormXObject ConvertToXObject(string content, PdfDocument document)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
Returns
- PdfFormXObject
a XObject containing the PDF instructions corresponding to the passed SVG content
Remarks
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToXObject(string, PdfDocument, ISvgConverterProperties)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument.
public static PdfFormXObject ConvertToXObject(string content, PdfDocument document, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
- PdfFormXObject
a XObject containing the PDF instructions corresponding to the passed SVG content
Remarks
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument . This method does NOT manipulate the PdfDocument in any way.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with ConvertToXObject(ISvgNodeRenderer, PdfDocument) , or look into using CopyTo(PdfDocument).ConvertToXObject(ISvgNodeRenderer, PdfDocument)
This method draws a NodeRenderer tree to a canvas that is tied to the passed document.
public static PdfFormXObject ConvertToXObject(ISvgNodeRenderer topSvgRenderer, PdfDocument document)
Parameters
topSvgRenderer
ISvgNodeRendererthe ISvgNodeRenderer instance that contains the renderer tree
document
PdfDocumentthe document that the returned XObject can be drawn on (on any given page coordinates)
Returns
- PdfFormXObject
an XObject containing the PDF instructions corresponding to the passed node renderer tree.
Remarks
This method draws a NodeRenderer tree to a canvas that is tied to the passed document.
This method (or its overloads) is the best method to use if you want to reuse the same SVG image multiple times on the same PdfDocument. If you want to reuse this object on other PdfDocument instances, please either use any of the Process(INode, ISvgConverterProperties) overloads in this same class and convert its result to an XObject with this method, or look into using CopyTo(PdfDocument).CreatePdf(FileInfo, FileInfo)
public static void CreatePdf(FileInfo svgFile, FileInfo pdfFile)
Parameters
svgFile
FileInfothe FileInfo containing the source SVG
pdfFile
FileInfothe FileInfo containing the resulting PDF
CreatePdf(FileInfo, FileInfo, WriterProperties)
Converts SVG stored in a FileInfo to a PDF FileInfo , using WriterProperties
public static void CreatePdf(FileInfo svgFile, FileInfo pdfFile, WriterProperties writerProps)
Parameters
svgFile
FileInfothe FileInfo containing the source SVG
pdfFile
FileInfothe FileInfo containing the resulting PDF
writerProps
WriterPropertiesthe WriterProperties for the pdf document
CreatePdf(FileInfo, FileInfo, ISvgConverterProperties)
Converts SVG stored in a FileInfo to a PDF FileInfo , using specific ISvgConverterProperties.
public static void CreatePdf(FileInfo svgFile, FileInfo pdfFile, ISvgConverterProperties props)
Parameters
svgFile
FileInfothe FileInfo containing the source SVG
pdfFile
FileInfothe FileInfo containing the resulting PDF
props
ISvgConverterPropertiesa ISvgConverterProperties an instance for extra properties to customize the behavior
CreatePdf(FileInfo, FileInfo, ISvgConverterProperties, WriterProperties)
Converts SVG stored in a FileInfo to a PDF FileInfo , using specific ISvgConverterProperties and WriterProperties.
public static void CreatePdf(FileInfo svgFile, FileInfo pdfFile, ISvgConverterProperties props, WriterProperties writerProps)
Parameters
svgFile
FileInfothe FileInfo containing the source SVG
pdfFile
FileInfothe FileInfo containing the resulting PDF
props
ISvgConverterPropertiesa ISvgConverterProperties an instance for extra properties to customize the behavior
writerProps
WriterPropertiesa WriterProperties for the pdf document
CreatePdf(Stream, Stream)
Create a single page pdf containing the SVG on its page using the default processing and drawing logic
public static void CreatePdf(Stream svgStream, Stream pdfDest)
Parameters
CreatePdf(Stream, Stream, WriterProperties)
Create a single page pdf containing the SVG on its page using the default processing and drawing logic
public static void CreatePdf(Stream svgStream, Stream pdfDest, WriterProperties writerProps)
Parameters
svgStream
StreamStream containing the SVG
pdfDest
StreamPDF destination outputStream
writerProps
WriterPropertieswriter properties for the pdf document
CreatePdf(Stream, Stream, ISvgConverterProperties)
Create a single page pdf containing the SVG on its page using the default processing and drawing logic
public static void CreatePdf(Stream svgStream, Stream pdfDest, ISvgConverterProperties props)
Parameters
svgStream
StreamStream containing the SVG
pdfDest
StreamPDF destination outputStream
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
CreatePdf(Stream, Stream, ISvgConverterProperties, WriterProperties)
Create a single page pdf containing the SVG on its page using the default processing and drawing logic
public static void CreatePdf(Stream svgStream, Stream pdfDest, ISvgConverterProperties props, WriterProperties writerProps)
Parameters
svgStream
StreamStream containing the SVG
pdfDest
StreamPDF destination outputStream
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
writerProps
WriterPropertiesWriterProperties for the pdf document
DrawOnCanvas(Stream, PdfCanvas)
Draws a Stream containing valid SVG to a pre-made canvas object.
public static void DrawOnCanvas(Stream stream, PdfCanvas canvas)
Parameters
stream
Streamthe Stream object containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
DrawOnCanvas(Stream, PdfCanvas, float, float)
Draws a Stream containing valid SVG to a pre-made canvas object, to a specified location.
public static void DrawOnCanvas(Stream stream, PdfCanvas canvas, float x, float y)
Parameters
stream
Streamthe Stream object containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnCanvas(Stream, PdfCanvas, float, float, ISvgConverterProperties)
Draws a String containing valid SVG to a pre-made canvas object, at a specified position on the canvas.
public static void DrawOnCanvas(Stream stream, PdfCanvas canvas, float x, float y, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream object containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnCanvas(Stream, PdfCanvas, ISvgConverterProperties)
Draws a Stream containing valid SVG to a pre-made canvas object.
public static void DrawOnCanvas(Stream stream, PdfCanvas canvas, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream object containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnCanvas(string, PdfCanvas)
Draws a String containing valid SVG to a pre-made canvas object.
public static void DrawOnCanvas(string content, PdfCanvas canvas)
Parameters
content
stringthe String value containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
DrawOnCanvas(string, PdfCanvas, float, float)
Draws a String containing valid SVG to a pre-made canvas object.
public static void DrawOnCanvas(string content, PdfCanvas canvas, float x, float y)
Parameters
content
stringthe String value containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnCanvas(string, PdfCanvas, float, float, ISvgConverterProperties)
draws a String containing valid SVG to a pre-made canvas object, at a specified location.
public static void DrawOnCanvas(string content, PdfCanvas canvas, float x, float y, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnCanvas(string, PdfCanvas, ISvgConverterProperties)
Draws a String containing valid SVG to a pre-made canvas object.
public static void DrawOnCanvas(string content, PdfCanvas canvas, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
canvas
PdfCanvasthe PdfCanvas instance to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnDocument(Stream, PdfDocument, int)
Draws a Stream containing valid SVG to a document, on a given page number ate the origni of the page.
public static void DrawOnDocument(Stream stream, PdfDocument document, int pageNo)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
DrawOnDocument(Stream, PdfDocument, int, float, float)
Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(Stream stream, PdfDocument document, int pageNo, float x, float y)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnDocument(Stream, PdfDocument, int, float, float, ISvgConverterProperties)
Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(Stream stream, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnDocument(Stream, PdfDocument, int, ISvgConverterProperties)
Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(Stream stream, PdfDocument document, int pageNo, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnDocument(string, PdfDocument, int)
Draws a String containing valid SVG to a document, on a given page number at the origin of the page.
public static void DrawOnDocument(string content, PdfDocument document, int pageNo)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
DrawOnDocument(string, PdfDocument, int, float, float)
Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(string content, PdfDocument document, int pageNo, float x, float y)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnDocument(string, PdfDocument, int, float, float, ISvgConverterProperties)
Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(string content, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnDocument(string, PdfDocument, int, ISvgConverterProperties)
Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.
public static void DrawOnDocument(string content, PdfDocument document, int pageNo, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
document
PdfDocumentthe PdfDocument instance to draw on
pageNo
intthe page to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnPage(Stream, PdfPage)
Draws a Stream containing valid SVG to a given page at coordinate 0,0.
public static void DrawOnPage(Stream stream, PdfPage page)
Parameters
stream
Streamthe Stream object containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
DrawOnPage(Stream, PdfPage, float, float)
Draws a Stream containing valid SVG to a given page, at a given location.
public static void DrawOnPage(Stream stream, PdfPage page, float x, float y)
Parameters
stream
Streamthe Stream object containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnPage(Stream, PdfPage, float, float, ISvgConverterProperties)
Draws a Stream containing valid SVG to a given page at a given location.
public static void DrawOnPage(Stream stream, PdfPage page, float x, float y, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream object containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnPage(Stream, PdfPage, ISvgConverterProperties)
Draws a Stream containing valid SVG to a given page at a given location.
public static void DrawOnPage(Stream stream, PdfPage page, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream object containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnPage(string, PdfPage)
Draws a String containing valid SVG to a given page at the origin of the page.
public static void DrawOnPage(string content, PdfPage page)
Parameters
content
stringthe String value containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
DrawOnPage(string, PdfPage, float, float)
Draws a String containing valid SVG to a given page on the provided x and y coordinate.
public static void DrawOnPage(string content, PdfPage page, float x, float y)
Parameters
content
stringthe String value containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
DrawOnPage(string, PdfPage, float, float, ISvgConverterProperties)
Draws a String containing valid SVG to a given page on the provided x and y coordinate.
public static void DrawOnPage(string content, PdfPage page, float x, float y, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
x
floatx-coordinate of the location to draw at
y
floaty-coordinate of the location to draw at
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
DrawOnPage(string, PdfPage, ISvgConverterProperties)
Draws a String containing valid SVG to a given page on the provided x and y coordinate.
public static void DrawOnPage(string content, PdfPage page, ISvgConverterProperties props)
Parameters
content
stringthe String value containing valid SVG content
page
PdfPagethe PdfPage instance to draw on
props
ISvgConverterPropertiesa container for extra properties that customize the behavior
ExtractWidthAndHeight(ISvgNodeRenderer)
Extract width and height of the passed SVGNodeRenderer, defaulting to respective viewbox values if either one is not present or to browser default if viewbox is missing as well
public static float[] ExtractWidthAndHeight(ISvgNodeRenderer topSvgRenderer)
Parameters
topSvgRenderer
ISvgNodeRendererthe ISvgNodeRenderer instance that contains the renderer tree
Returns
- float[]
float[2], width is in position 0, height in position 1
Parse(Stream)
Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.
public static INode Parse(Stream stream)
Parameters
Returns
- INode
an XML DOM tree corresponding to the passed String input
Remarks
Parse a Stream containing valid SVG into an XML DOM node, using the
default JSoup XML parser. This method will assume that the encoding of
the Stream is
UTF-8
.
Parse(Stream, ISvgConverterProperties)
Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.
public static INode Parse(Stream stream, ISvgConverterProperties props)
Parameters
stream
Streamthe Stream containing valid SVG content
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
- INode
an XML DOM tree corresponding to the passed String input
Remarks
Parse a Stream containing valid SVG into an XML DOM node, using the
default JSoup XML parser. This method will assume that the encoding of
the Stream is
UTF-8
, unless specified otherwise by the method
GetCharset()
of the
props
parameter.
Parse(string)
Parse a String containing valid SVG into an XML DOM node, using the default JSoup XML parser.
public static INode Parse(string content)
Parameters
content
stringthe String value containing valid SVG content
Returns
- INode
an XML DOM tree corresponding to the passed String input
ParseAndProcess(Stream)
Parse and process an Inputstream containing an SVG, using the default Svg processor ( DefaultSvgProcessor ) The parsing of the stream is done using UTF-8 as the default charset.
public static ISvgProcessorResult ParseAndProcess(Stream svgStream)
Parameters
Returns
- ISvgProcessorResult
ISvgProcessorResult containing the root renderer and metadata of the svg
Remarks
Parse and process an Inputstream containing an SVG, using the default Svg processor ( DefaultSvgProcessor ) The parsing of the stream is done using UTF-8 as the default charset. The properties used by the processor are the SvgConverterProperties
ParseAndProcess(Stream, ISvgConverterProperties)
Parse and process an Inputstream containing an SVG, using the default Svg processor ( DefaultSvgProcessor )
public static ISvgProcessorResult ParseAndProcess(Stream svgStream, ISvgConverterProperties props)
Parameters
svgStream
StreamStream containing the SVG to parse and process
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
- ISvgProcessorResult
ISvgProcessorResult containing the root renderer and metadata of the svg
Process(INode, ISvgConverterProperties)
Use the default implementation of ISvgProcessor to convert an XML DOM tree to a node renderer tree.
public static ISvgProcessorResult Process(INode root, ISvgConverterProperties props)
Parameters
root
INodethe XML DOM tree
props
ISvgConverterPropertiesISvgConverterProperties an instance for extra properties to customize the behavior
Returns
- ISvgProcessorResult
a node renderer tree corresponding to the passed XML DOM tree
Remarks
Use the default implementation of ISvgProcessor to convert an XML DOM tree to a node renderer tree. The passed properties can modify the default behaviour