Class SvgConverter
-
Method Summary
Modifier and TypeMethodDescriptionstatic Image
convertToImage
(InputStream stream, PdfDocument document) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
.static Image
convertToImage
(InputStream stream, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to animage
that can then be used on the passedPdfDocument
.static PdfFormXObject
convertToXObject
(ISvgNodeRenderer topSvgRenderer, PdfDocument document) This method draws a NodeRenderer tree to a canvas that is tied to the passed document.static PdfFormXObject
convertToXObject
(InputStream stream, PdfDocument document) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
.static PdfFormXObject
convertToXObject
(InputStream stream, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
.static PdfFormXObject
convertToXObject
(String content, PdfDocument document) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
.static PdfFormXObject
convertToXObject
(String content, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
.static void
static void
createPdf
(File svgFile, File pdfFile, WriterProperties writerProps) static void
createPdf
(File svgFile, File pdfFile, ISvgConverterProperties props) static void
createPdf
(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps) Converts SVG stored in aFile
to a PDFFile
, using specificISvgConverterProperties
andWriterProperties
.static void
createPdf
(InputStream svgStream, OutputStream pdfDest) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic void
createPdf
(InputStream svgStream, OutputStream pdfDest, WriterProperties writerProps) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic void
createPdf
(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic void
createPdf
(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props, WriterProperties writerProps) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic void
drawOnCanvas
(InputStream stream, PdfCanvas canvas) Draws a Stream containing valid SVG to a pre-made canvas object.static void
drawOnCanvas
(InputStream stream, PdfCanvas canvas, float x, float y) Draws a Stream containing valid SVG to a pre-made canvas object, to a specified location.static void
drawOnCanvas
(InputStream stream, PdfCanvas canvas, float x, float y, ISvgConverterProperties props) Draws a String containing valid SVG to a pre-made canvas object, at a specified position on the canvas.static void
drawOnCanvas
(InputStream stream, PdfCanvas canvas, ISvgConverterProperties props) Draws a Stream containing valid SVG to a pre-made canvas object.static void
drawOnCanvas
(String content, PdfCanvas canvas) Draws a String containing valid SVG to a pre-made canvas object.static void
drawOnCanvas
(String content, PdfCanvas canvas, float x, float y) Draws a String containing valid SVG to a pre-made canvas object.static void
drawOnCanvas
(String content, PdfCanvas canvas, float x, float y, ISvgConverterProperties props) draws a String containing valid SVG to a pre-made canvas object, at a specified location.static void
drawOnCanvas
(String content, PdfCanvas canvas, ISvgConverterProperties props) Draws a String containing valid SVG to a pre-made canvas object.static void
drawOnDocument
(InputStream stream, PdfDocument document, int pageNo) Draws a Stream containing valid SVG to a document, on a given page number ate the origni of the page.static void
drawOnDocument
(InputStream stream, PdfDocument document, int pageNo, float x, float y) Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnDocument
(InputStream stream, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props) Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnDocument
(InputStream stream, PdfDocument document, int pageNo, ISvgConverterProperties props) Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnDocument
(String content, PdfDocument document, int pageNo) Draws a String containing valid SVG to a document, on a given page number at the origin of the page.static void
drawOnDocument
(String content, PdfDocument document, int pageNo, float x, float y) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnDocument
(String content, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnDocument
(String content, PdfDocument document, int pageNo, ISvgConverterProperties props) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.static void
drawOnPage
(InputStream stream, PdfPage page) Draws a Stream containing valid SVG to a given page at coordinate 0,0.static void
drawOnPage
(InputStream stream, PdfPage page, float x, float y) Draws a Stream containing valid SVG to a given page, at a given location.static void
drawOnPage
(InputStream stream, PdfPage page, float x, float y, ISvgConverterProperties props) Draws a Stream containing valid SVG to a given page at a given location.static void
drawOnPage
(InputStream stream, PdfPage page, ISvgConverterProperties props) Draws a Stream containing valid SVG to a given page at a given location.static void
drawOnPage
(String content, PdfPage page) Draws a String containing valid SVG to a given page at the origin of the page.static void
drawOnPage
(String content, PdfPage page, float x, float y) Draws a String containing valid SVG to a given page on the provided x and y coordinate.static void
drawOnPage
(String content, PdfPage page, float x, float y, ISvgConverterProperties props) Draws a String containing valid SVG to a given page on the provided x and y coordinate.static void
drawOnPage
(String content, PdfPage page, ISvgConverterProperties props) Draws a String containing valid SVG to a given page on the provided x and y coordinate.static float[]
extractWidthAndHeight
(ISvgNodeRenderer topSvgRenderer) 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 wellstatic INode
parse
(InputStream stream) Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.static INode
parse
(InputStream stream, ISvgConverterProperties props) Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.static INode
Parse a String containing valid SVG into an XML DOM node, using the default JSoup XML parser.static ISvgProcessorResult
parseAndProcess
(InputStream svgStream) 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.static ISvgProcessorResult
parseAndProcess
(InputStream svgStream, ISvgConverterProperties props) Parse and process an Inputstream containing an SVG, using the default Svg processor (DefaultSvgProcessor
)static ISvgProcessorResult
process
(INode root, ISvgConverterProperties props) Use the default implementation ofISvgProcessor
to convert an XML DOM tree to a node renderer tree.
-
Method Details
-
drawOnDocument
Draws a String containing valid SVG to a document, on a given page number at the origin of the page.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on
-
drawOnDocument
public static void drawOnDocument(String content, PdfDocument document, int pageNo, float x, float y) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at
-
drawOnDocument
public static void drawOnDocument(String content, PdfDocument document, int pageNo, ISvgConverterProperties props) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
props
- a container for extra properties that customize the behavior
-
drawOnDocument
public static void drawOnDocument(String content, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props) Draws a String containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior
-
drawOnDocument
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo) throws IOException Draws a Stream containing valid SVG to a document, on a given page number ate the origni of the page.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnDocument
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, float x, float y) throws IOException Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnDocument
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, ISvgConverterProperties props) throws IOException Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnDocument
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props) throws IOException Draws a Stream containing valid SVG to a document, on a given page number on the provided x and y coordinate.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
pageNo
- the page to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnPage
Draws a String containing valid SVG to a given page at the origin of the page.- Parameters:
-
content
- the String value containing valid SVG content -
page
- thePdfPage
instance to draw on
-
drawOnPage
Draws a String containing valid SVG to a given page on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
page
- thePdfPage
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at
-
drawOnPage
Draws a String containing valid SVG to a given page on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
page
- thePdfPage
instance to draw on -
props
- a container for extra properties that customize the behavior
-
drawOnPage
public static void drawOnPage(String content, PdfPage page, float x, float y, ISvgConverterProperties props) Draws a String containing valid SVG to a given page on the provided x and y coordinate.- Parameters:
-
content
- the String value containing valid SVG content -
page
- thePdfPage
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior
-
drawOnPage
Draws a Stream containing valid SVG to a given page at coordinate 0,0.- Parameters:
-
stream
- theStream
object containing valid SVG content -
page
- thePdfPage
instance to draw on - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnPage
public static void drawOnPage(InputStream stream, PdfPage page, float x, float y) throws IOException Draws a Stream containing valid SVG to a given page, at a given location.- Parameters:
-
stream
- theStream
object containing valid SVG content -
page
- thePdfPage
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnPage
public static void drawOnPage(InputStream stream, PdfPage page, ISvgConverterProperties props) throws IOException Draws a Stream containing valid SVG to a given page at a given location.- Parameters:
-
stream
- theStream
object containing valid SVG content -
page
- thePdfPage
instance to draw on -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnPage
public static void drawOnPage(InputStream stream, PdfPage page, float x, float y, ISvgConverterProperties props) throws IOException Draws a Stream containing valid SVG to a given page at a given location.- Parameters:
-
stream
- theStream
object containing valid SVG content -
page
- thePdfPage
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnCanvas
Draws a String containing valid SVG to a pre-made canvas object.- Parameters:
-
content
- the String value containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on
-
drawOnCanvas
Draws a String containing valid SVG to a pre-made canvas object.- Parameters:
-
content
- the String value containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at
-
drawOnCanvas
Draws a String containing valid SVG to a pre-made canvas object.- Parameters:
-
content
- the String value containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
props
- a container for extra properties that customize the behavior
-
drawOnCanvas
public static void drawOnCanvas(String content, PdfCanvas canvas, float x, float y, ISvgConverterProperties props) draws a String containing valid SVG to a pre-made canvas object, at a specified location.- Parameters:
-
content
- the String value containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior
-
drawOnCanvas
Draws a Stream containing valid SVG to a pre-made canvas object.- Parameters:
-
stream
- theStream
object containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnCanvas
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, float x, float y) throws IOException Draws a Stream containing valid SVG to a pre-made canvas object, to a specified location.- Parameters:
-
stream
- theStream
object containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnCanvas
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, ISvgConverterProperties props) throws IOException Draws a Stream containing valid SVG to a pre-made canvas object.- Parameters:
-
stream
- theStream
object containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
drawOnCanvas
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, float x, float y, ISvgConverterProperties props) throws IOException Draws a String containing valid SVG to a pre-made canvas object, at a specified position on the canvas.- Parameters:
-
stream
- theStream
object containing valid SVG content -
canvas
- thePdfCanvas
instance to draw on -
x
- x-coordinate of the location to draw at -
y
- y-coordinate of the location to draw at -
props
- a container for extra properties that customize the behavior - Throws:
-
IOException
- when the Stream cannot be read correctly
-
createPdf
- Parameters:
-
svgFile
- theFile
containing the source SVG -
pdfFile
- theFile
containing the resulting PDF - Throws:
-
IOException
- Signals that an I/O exception has occurred.
-
createPdf
public static void createPdf(File svgFile, File pdfFile, ISvgConverterProperties props) throws IOException - Parameters:
-
svgFile
- theFile
containing the source SVG -
pdfFile
- theFile
containing the resulting PDF -
props
- aISvgConverterProperties
an instance for extra properties to customize the behavior - Throws:
-
IOException
- Signals that an I/O exception has occurred.
-
createPdf
public static void createPdf(File svgFile, File pdfFile, WriterProperties writerProps) throws IOException - Parameters:
-
svgFile
- theFile
containing the source SVG -
pdfFile
- theFile
containing the resulting PDF -
writerProps
- theWriterProperties
for the pdf document - Throws:
-
IOException
- Signals that an I/O exception has occurred.
-
createPdf
public static void createPdf(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps) throws IOException Converts SVG stored in aFile
to a PDFFile
, using specificISvgConverterProperties
andWriterProperties
.- Parameters:
-
svgFile
- theFile
containing the source SVG -
pdfFile
- theFile
containing the resulting PDF -
props
- aISvgConverterProperties
an instance for extra properties to customize the behavior -
writerProps
- aWriterProperties
for the pdf document - Throws:
-
IOException
- Signals that an I/O exception has occurred.
-
createPdf
Create a single page pdf containing the SVG on its page using the default processing and drawing logic- Parameters:
-
svgStream
-Stream
containing the SVG -
pdfDest
- PDF destination outputStream - Throws:
-
IOException
- when the one of the streams cannot be read correctly
-
createPdf
public static void createPdf(InputStream svgStream, OutputStream pdfDest, WriterProperties writerProps) throws IOException Create a single page pdf containing the SVG on its page using the default processing and drawing logic- Parameters:
-
svgStream
-Stream
containing the SVG -
pdfDest
- PDF destination outputStream -
writerProps
- writer properties for the pdf document - Throws:
-
IOException
- when the one of the streams cannot be read correctly
-
createPdf
public static void createPdf(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props) throws IOException Create a single page pdf containing the SVG on its page using the default processing and drawing logic- Parameters:
-
svgStream
-Stream
containing the SVG -
pdfDest
- PDF destination outputStream -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Throws:
-
IOException
- when the one of the streams cannot be read correctly
-
createPdf
public static void createPdf(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props, WriterProperties writerProps) throws IOException Create a single page pdf containing the SVG on its page using the default processing and drawing logic- Parameters:
-
svgStream
-Stream
containing the SVG -
pdfDest
- PDF destination outputStream -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior -
writerProps
-WriterProperties
for the pdf document - Throws:
-
IOException
- when the one of the streams cannot be read correctly
-
convertToXObject
Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on - Returns:
-
a
XObject
containing the PDF instructions corresponding to the passed SVG content
-
convertToXObject
public static PdfFormXObject convertToXObject(String content, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
content
- the String value containing valid SVG content -
document
- thePdfDocument
instance to draw on -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
-
a
XObject
containing the PDF instructions corresponding to the passed SVG content
-
convertToXObject
public static PdfFormXObject convertToXObject(InputStream stream, PdfDocument document, ISvgConverterProperties props) throws IOException Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
-
a
XObject
containing the PDF instructions corresponding to the passed SVG content - Throws:
-
IOException
- when the stream cannot be read correctly
-
convertToXObject
public static PdfFormXObject convertToXObject(InputStream stream, PdfDocument document) throws IOException Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on - Returns:
-
a
XObject
containing the PDF instructions corresponding to the passed SVG content - Throws:
-
IOException
- when the Stream cannot be read correctly
-
convertToImage
Converts a String containing valid SVG content to anXObject
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on - Returns:
-
a
Image
containing the PDF instructions corresponding to the passed SVG content - Throws:
-
IOException
- when the Stream cannot be read correctly
-
convertToImage
public static Image convertToImage(InputStream stream, PdfDocument document, ISvgConverterProperties props) throws IOException Converts a String containing valid SVG content to animage
that can then be used on the passedPdfDocument
. This method does NOT manipulate thePdfDocument
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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject withconvertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
stream
- theStream
containing valid SVG content -
document
- thePdfDocument
instance to draw on -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
-
a
Image
containing the PDF instructions corresponding to the passed SVG content - Throws:
-
IOException
- when the Stream cannot be read correctly
-
convertToXObject
public static PdfFormXObject convertToXObject(ISvgNodeRenderer topSvgRenderer, PdfDocument document) 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 theprocess(com.itextpdf.styledxmlparser.node.INode, com.itextpdf.svg.processors.ISvgConverterProperties)
overloads in this same class and convert its result to an XObject with this method, or look into usingPdfObject.copyTo(PdfDocument)
.- Parameters:
-
topSvgRenderer
- theISvgNodeRenderer
instance that contains the renderer tree -
document
- the document that the returnedXObject
can be drawn on (on any given page coordinates) - Returns:
-
an
XObject
containing the PDF instructions corresponding to the passed node renderer tree.
-
parseAndProcess
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 theSvgConverterProperties
- Parameters:
-
svgStream
-Stream
containing the SVG to parse and process - Returns:
-
ISvgProcessorResult
containing the root renderer and metadata of the svg
-
parseAndProcess
public static ISvgProcessorResult parseAndProcess(InputStream svgStream, ISvgConverterProperties props) Parse and process an Inputstream containing an SVG, using the default Svg processor (DefaultSvgProcessor
)- Parameters:
-
svgStream
-Stream
containing the SVG to parse and process -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
-
ISvgProcessorResult
containing the root renderer and metadata of the svg
-
process
Use the default implementation ofISvgProcessor
to convert an XML DOM tree to a node renderer tree. The passed properties can modify the default behaviour- Parameters:
-
root
- the XML DOM tree -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
- a node renderer tree corresponding to the passed XML DOM tree
-
parse
Parse a String containing valid SVG into an XML DOM node, using the default JSoup XML parser.- Parameters:
-
content
- the String value containing valid SVG content - Returns:
- an XML DOM tree corresponding to the passed String input
-
parse
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 isUTF-8
.- Parameters:
-
stream
- theStream
containing valid SVG content - Returns:
- an XML DOM tree corresponding to the passed String input
- Throws:
-
IOException
- when the Stream cannot be read correctly
-
parse
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 isUTF-8
, unless specified otherwise by the methodISvgConverterProperties.getCharset()
of theprops
parameter.- Parameters:
-
stream
- theStream
containing valid SVG content -
props
-ISvgConverterProperties
an instance for extra properties to customize the behavior - Returns:
- an XML DOM tree corresponding to the passed String input
- Throws:
-
IOException
- when the Stream cannot be read correctly
-
extractWidthAndHeight
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- Parameters:
-
topSvgRenderer
- theISvgNodeRenderer
instance that contains the renderer tree - Returns:
- float[2], width is in position 0, height in position 1
-