Table of Contents

Class SvgConverter

Namespace
iText.Svg.Converter
Assembly
itext.svg.dll

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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

Returns

Image

a Image 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).

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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

props ISvgConverterProperties

ISvgConverterProperties an instance for extra properties to customize the behavior

Returns

Image

a Image containing the PDF instructions corresponding to the passed SVG content

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 Stream

the Stream containing valid SVG content

document PdfDocument

the 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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

props ISvgConverterProperties

ISvgConverterProperties 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 string

the String value containing valid SVG content

document PdfDocument

the 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 string

the String value containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

props ISvgConverterProperties

ISvgConverterProperties 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 ISvgNodeRenderer

the ISvgNodeRenderer instance that contains the renderer tree

document PdfDocument

the 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)

Converts SVG stored in a FileInfo to a PDF FileInfo.

public static void CreatePdf(FileInfo svgFile, FileInfo pdfFile)

Parameters

svgFile FileInfo

the FileInfo containing the source SVG

pdfFile FileInfo

the 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 FileInfo

the FileInfo containing the source SVG

pdfFile FileInfo

the FileInfo containing the resulting PDF

writerProps WriterProperties

the 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 FileInfo

the FileInfo containing the source SVG

pdfFile FileInfo

the FileInfo containing the resulting PDF

props ISvgConverterProperties

a 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 FileInfo

the FileInfo containing the source SVG

pdfFile FileInfo

the FileInfo containing the resulting PDF

props ISvgConverterProperties

a ISvgConverterProperties an instance for extra properties to customize the behavior

writerProps WriterProperties

a 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

svgStream Stream

Stream containing the SVG

pdfDest Stream

PDF destination outputStream

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 Stream

Stream containing the SVG

pdfDest Stream

PDF destination outputStream

writerProps WriterProperties

writer 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 Stream

Stream containing the SVG

pdfDest Stream

PDF destination outputStream

props ISvgConverterProperties

ISvgConverterProperties 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 Stream

Stream containing the SVG

pdfDest Stream

PDF destination outputStream

props ISvgConverterProperties

ISvgConverterProperties an instance for extra properties to customize the behavior

writerProps WriterProperties

WriterProperties 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 Stream

the Stream object containing valid SVG content

canvas PdfCanvas

the 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 Stream

the Stream object containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

x float

x-coordinate of the location to draw at

y float

y-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 Stream

the Stream object containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 Stream

the Stream object containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

canvas PdfCanvas

the 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 string

the String value containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

x float

x-coordinate of the location to draw at

y float

y-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 string

the String value containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

canvas PdfCanvas

the PdfCanvas instance to draw on

props ISvgConverterProperties

a 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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the 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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

x float

x-coordinate of the location to draw at

y float

y-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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 Stream

the Stream containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the 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 string

the String value containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

x float

x-coordinate of the location to draw at

y float

y-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 string

the String value containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

document PdfDocument

the PdfDocument instance to draw on

pageNo int

the page to draw on

props ISvgConverterProperties

a 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 Stream

the Stream object containing valid SVG content

page PdfPage

the 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 Stream

the Stream object containing valid SVG content

page PdfPage

the PdfPage instance to draw on

x float

x-coordinate of the location to draw at

y float

y-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 Stream

the Stream object containing valid SVG content

page PdfPage

the PdfPage instance to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 Stream

the Stream object containing valid SVG content

page PdfPage

the PdfPage instance to draw on

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

page PdfPage

the 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 string

the String value containing valid SVG content

page PdfPage

the PdfPage instance to draw on

x float

x-coordinate of the location to draw at

y float

y-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 string

the String value containing valid SVG content

page PdfPage

the PdfPage instance to draw on

x float

x-coordinate of the location to draw at

y float

y-coordinate of the location to draw at

props ISvgConverterProperties

a 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 string

the String value containing valid SVG content

page PdfPage

the PdfPage instance to draw on

props ISvgConverterProperties

a 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 ISvgNodeRenderer

the 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

stream Stream

the Stream containing valid SVG content

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 Stream

the Stream containing valid SVG content

props ISvgConverterProperties

ISvgConverterProperties 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 string

the 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

svgStream Stream

Stream containing the SVG to parse and process

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 Stream

Stream containing the SVG to parse and process

props ISvgConverterProperties

ISvgConverterProperties 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 INode

the XML DOM tree

props ISvgConverterProperties

ISvgConverterProperties 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