public final class SvgConverter extends Object
Modifier and Type | Method and Description |
---|---|
static Image |
convertToImage(InputStream stream, PdfDocument document)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument .
|
static Image |
convertToImage(InputStream stream, PdfDocument document, ISvgConverterProperties props)
Converts a String containing valid SVG content to an image that can then be used on the passed PdfDocument .
|
static PdfFormXObject |
convertToXObject(InputStream stream, PdfDocument document)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument .
|
static PdfFormXObject |
convertToXObject(InputStream stream, PdfDocument document, ISvgConverterProperties props)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument .
|
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(String content, PdfDocument document)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument .
|
static PdfFormXObject |
convertToXObject(String content, PdfDocument document, ISvgConverterProperties props)
Converts a String containing valid SVG content to an XObject that can then be used on the passed PdfDocument .
|
static void |
createPdf(File svgFile, File pdfFile)
|
static void |
createPdf(File svgFile, File pdfFile, ISvgConverterProperties props)
|
static void |
createPdf(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps)
Converts SVG stored in a File to a PDF File , using specific ISvgConverterProperties and WriterProperties .
|
static void |
createPdf(File svgFile, File pdfFile, WriterProperties writerProps)
|
static void |
createPdf(InputStream svgStream, OutputStream pdfDest)
Create a single page pdf containing the SVG on its page using the default processing and drawing logic
|
static 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 logic
|
static 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 logic
|
static 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 logic
|
static 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 well
|
static 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(String content)
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)
Deprecated.
will be removed in iText 7.2.
|
static ISvgProcessorResult |
process(INode root, ISvgConverterProperties props)
Use the default implementation of ISvgProcessor to convert an XML DOM tree to a node renderer tree.
|
public static void drawOnDocument(String content, PdfDocument document, int pageNo)
content
- the String value containing valid SVG content
document
- the PdfDocument
instance to draw on
pageNo
- the page to draw on
public static void drawOnDocument(String content, PdfDocument document, int pageNo, float x, float y)
content
- the String value containing valid SVG content
document
- the PdfDocument
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
public static void drawOnDocument(String content, PdfDocument document, int pageNo, ISvgConverterProperties props)
content
- the Stream object containing valid SVG content
document
- the PdfDocument
instance to draw on
pageNo
- the page to draw on
props
- a container for extra properties that customize the behavior
public static void drawOnDocument(String content, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props)
content
- the Stream object containing valid SVG content
document
- the PdfDocument
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
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo) throws IOException
stream
- the Stream object containing valid SVG content
document
- the PdfDocument
instance to draw on
pageNo
- the page to draw on
IOException
- when the Stream cannot be read correctly
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, float x, float y) throws IOException
stream
- the Stream object containing valid SVG content
document
- the PdfDocument
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
IOException
- when the Stream cannot be read correctly
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, ISvgConverterProperties props) throws IOException
stream
- the Stream object containing valid SVG content
document
- the PdfDocument
instance to draw on
pageNo
- the page to draw on
props
- a container for extra properties that customize the behavior
IOException
- when the Stream cannot be read correctly
public static void drawOnDocument(InputStream stream, PdfDocument document, int pageNo, float x, float y, ISvgConverterProperties props) throws IOException
stream
- the Stream object containing valid SVG content
document
- the PdfDocument
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
IOException
- when the Stream cannot be read correctly
public static void drawOnPage(String content, PdfPage page)
content
- the String value containing valid SVG content
page
- the PdfPage
instance to draw on
public static void drawOnPage(String content, PdfPage page, float x, float y)
content
- the String value containing valid SVG content
page
- the PdfPage
instance to draw on
x
- x-coordinate of the location to draw at
y
- y-coordinate of the location to draw at
public static void drawOnPage(String content, PdfPage page, ISvgConverterProperties props)
content
- the String value containing valid SVG content
page
- the PdfPage
instance to draw on
props
- a container for extra properties that customize the behavior
public static void drawOnPage(String content, PdfPage page, float x, float y, ISvgConverterProperties props)
content
- the String value containing valid SVG content
page
- the PdfPage
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
public static void drawOnPage(InputStream stream, PdfPage page) throws IOException
stream
- the Stream
object containing valid SVG content
page
- the PdfPage
instance to draw on
IOException
- when the Stream cannot be read correctly
public static void drawOnPage(InputStream stream, PdfPage page, float x, float y) throws IOException
stream
- the Stream
object containing valid SVG content
page
- the PdfPage
instance to draw on
x
- x-coordinate of the location to draw at
y
- y-coordinate of the location to draw at
IOException
- when the Stream cannot be read correctly
public static void drawOnPage(InputStream stream, PdfPage page, ISvgConverterProperties props) throws IOException
stream
- the Stream
object containing valid SVG content
page
- the PdfPage
instance to draw on
props
- a container for extra properties that customize the behavior
IOException
- when the Stream cannot be read correctly
public static void drawOnPage(InputStream stream, PdfPage page, float x, float y, ISvgConverterProperties props) throws IOException
stream
- the Stream
object containing valid SVG content
page
- the PdfPage
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
IOException
- when the Stream cannot be read correctly
public static void drawOnCanvas(String content, PdfCanvas canvas)
content
- the String value containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
public static void drawOnCanvas(String content, PdfCanvas canvas, float x, float y)
content
- the String value containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
x
- x-coordinate of the location to draw at
y
- y-coordinate of the location to draw at
public static void drawOnCanvas(String content, PdfCanvas canvas, ISvgConverterProperties props)
content
- the String value containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
props
- a container for extra properties that customize the behavior
public static void drawOnCanvas(String content, PdfCanvas canvas, float x, float y, ISvgConverterProperties props)
content
- the String value containing valid SVG content
canvas
- the PdfCanvas
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
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas) throws IOException
stream
- the Stream
object containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
IOException
- when the Stream cannot be read correctly
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, float x, float y) throws IOException
stream
- the Stream
object containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
x
- x-coordinate of the location to draw at
y
- y-coordinate of the location to draw at
IOException
- when the Stream cannot be read correctly
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, ISvgConverterProperties props) throws IOException
stream
- the Stream
object containing valid SVG content
canvas
- the PdfCanvas
instance to draw on
props
- a container for extra properties that customize the behavior
IOException
- when the Stream cannot be read correctly
public static void drawOnCanvas(InputStream stream, PdfCanvas canvas, float x, float y, ISvgConverterProperties props) throws IOException
stream
- the Stream
object containing valid SVG content
canvas
- the PdfCanvas
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
IOException
- when the Stream cannot be read correctly
public static void createPdf(File svgFile, File pdfFile) throws IOException
svgFile
- the File
containing the source SVG
pdfFile
- the File
containing the resulting PDF
IOException
- Signals that an I/O exception has occurred.
public static void createPdf(File svgFile, File pdfFile, ISvgConverterProperties props) throws IOException
svgFile
- the File
containing the source SVG
pdfFile
- the File
containing the resulting PDF
props
- a ISvgConverterProperties
instance
IOException
- Signals that an I/O exception has occurred.
public static void createPdf(File svgFile, File pdfFile, WriterProperties writerProps) throws IOException
svgFile
- the File
containing the source SVG
pdfFile
- the File
containing the resulting PDF
writerProps
- theWriterProperties
for the pdf document
IOException
- Signals that an I/O exception has occurred.
public static void createPdf(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps) throws IOException
File
to a PDF File
, using specific ISvgConverterProperties
and WriterProperties
.
svgFile
- the File
containing the source SVG
pdfFile
- the File
containing the resulting PDF
props
- a ISvgConverterProperties
instance
writerProps
- a WriterProperties
for the pdf document
IOException
- Signals that an I/O exception has occurred.
public static void createPdf(InputStream svgStream, OutputStream pdfDest) throws IOException
svgStream
- Stream
containing the SVG
pdfDest
- PDF destination outputStream
IOException
- when the one of the streams cannot be read correctly
public static void createPdf(InputStream svgStream, OutputStream pdfDest, WriterProperties writerprops) throws IOException
svgStream
- Stream
containing the SVG
pdfDest
- PDF destination outputStream
writerprops
- writerproperties for the pdf document
IOException
- when the one of the streams cannot be read correctly
public static void createPdf(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props) throws IOException
svgStream
- Stream
containing the SVG
pdfDest
- PDF destination outputStream
props
- Svg ISvgConverterProperties
to change default behaviour
IOException
- when the one of the streams cannot be read correctly
public static void createPdf(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props, WriterProperties writerProps) throws IOException
svgStream
- Stream
containing the SVG
props
- ISvgConverterProperties
to change default behaviour
pdfDest
- PDF destination outputStream
writerProps
- WriterProperties
for the pdf document
IOException
- when the one of the streams cannot be read correctly public static void createPdf(InputStream svgStream,ISvgConverterProperties props, OutputStream pdfDest) throws IOException { createPdf(svgStream,props,pdfDest,null); }
/** Create a single page pdf containing the SVG on its page using the default processing and drawing logic
IOException
- when the one of the streams cannot be read correctly
public static PdfFormXObject convertToXObject(String content, PdfDocument document)
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
content
- the String value containing valid SVG content
document
- the PdfDocument
instance to draw on
XObject
containing the PDF instructions corresponding to the passed SVG content
public static PdfFormXObject convertToXObject(String content, PdfDocument document, ISvgConverterProperties props)
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
content
- the String value containing valid SVG content
document
- the PdfDocument
instance to draw on
props
- ISvgConverterProperties
to customize the behavior
XObject
containing the PDF instructions corresponding to the passed SVG content
public static PdfFormXObject convertToXObject(InputStream stream, PdfDocument document, ISvgConverterProperties props) throws IOException
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
stream
- the Stream
object containing valid SVG content
document
- the PdfDocument
instance to draw on
props
- ISvgConverterProperties
to customize the behavior
XObject
containing the PDF instructions corresponding to the passed SVG content
IOException
- when the Stream cannot be read correctly
public static PdfFormXObject convertToXObject(InputStream stream, PdfDocument document) throws IOException
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
stream
- the Stream
object containing valid SVG content
document
- the PdfDocument
instance to draw on
XObject
containing the PDF instructions corresponding to the passed SVG content
IOException
- when the Stream cannot be read correctly
public static Image convertToImage(InputStream stream, PdfDocument document) throws IOException
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
stream
- the Stream object containing valid SVG content
document
- the PdfDocument
instance to draw on
Image
containing the PDF instructions corresponding to the passed SVG content
IOException
- when the Stream cannot be read correctly
public static Image convertToImage(InputStream stream, PdfDocument document, ISvgConverterProperties props) throws IOException
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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with convertToXObject(ISvgNodeRenderer, PdfDocument)
, or look into using PdfObject.copyTo(PdfDocument)
.
stream
- the Stream
object containing valid SVG content
document
- the PdfDocument
instance to draw on
props
- ISvgConverterProperties
to customize the behavior
Image
containing the PDF instructions corresponding to the passed SVG content
IOException
- when the Stream cannot be read correctly
public static PdfFormXObject convertToXObject(ISvgNodeRenderer topSvgRenderer, PdfDocument 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(com.itextpdf.styledxmlparser.node.INode)
overloads in this same class and convert its result to an XObject with this method, or look into using PdfObject.copyTo(PdfDocument)
.
topSvgRenderer
- the ISvgNodeRenderer
instance that contains the renderer tree
document
- the document that the returned XObject
can be drawn on (on any given page coordinates)
XObject
containing the PDF instructions corresponding to the passed node renderer tree.
public static ISvgProcessorResult parseAndProcess(InputStream svgStream) throws IOException
DefaultSvgProcessor
) The parsing of the stream is done using UTF-8 as the default charset. The properties used by the processor are the SvgConverterProperties
svgStream
- Input stream containing the SVG to parse and process
ISvgProcessorResult
containing the root renderer and metadata of the svg
IOException
- when the Stream cannot be read correctly
public static ISvgProcessorResult parseAndProcess(InputStream svgStream, ISvgConverterProperties props) throws IOException
DefaultSvgProcessor
)
svgStream
- Stream
containing the SVG to parse and process
props
- ISvgConverterProperties
used by the processor
ISvgProcessorResult
containing the root renderer and metadata of the svg
IOException
- when the Stream cannot be read correctly
@Deprecated public static ISvgProcessorResult process(INode root)
ISvgProcessor
to convert an XML DOM tree to a node renderer tree.
root
- the XML DOM tree
public static ISvgProcessorResult process(INode root, ISvgConverterProperties props)
ISvgProcessor
to convert an XML DOM tree to a node renderer tree. The passed properties can modify the default behaviour
root
- the XML DOM tree
props
- ISvgConverterProperties
to customize the behavior
public static INode parse(String content)
content
- the String value containing valid SVG content
public static INode parse(InputStream stream) throws IOException
UTF-8
.
stream
- the Stream
object containing valid SVG content
IOException
- when the Stream cannot be read correctly
public static INode parse(InputStream stream, ISvgConverterProperties props) throws IOException
UTF-8
, unless specified otherwise by the method ISvgConverterProperties.getCharset()
of the props
parameter.
stream
- the Stream
object containing valid SVG content
props
- ISvgConverterProperties
to customize the behavior
IOException
- when the Stream cannot be read correctly
public static float[] extractWidthAndHeight(ISvgNodeRenderer topSvgRenderer)
topSvgRenderer
-
Copyright © 1998–2020 iText Group NV. All rights reserved.