Class SvgConverter
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageconvertToImage(InputStream stream, PdfDocument document) Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument.static ImageconvertToImage(InputStream stream, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to animagethat can then be used on the passedPdfDocument.static PdfFormXObjectconvertToXObject(ISvgNodeRenderer topSvgRenderer, PdfDocument document) This method draws a NodeRenderer tree to a canvas that is tied to the passed document.static PdfFormXObjectconvertToXObject(InputStream stream, PdfDocument document) Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument.static PdfFormXObjectconvertToXObject(InputStream stream, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument.static PdfFormXObjectconvertToXObject(String content, PdfDocument document) Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument.static PdfFormXObjectconvertToXObject(String content, PdfDocument document, ISvgConverterProperties props) Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument.static voidstatic voidcreatePdf(File svgFile, File pdfFile, WriterProperties writerProps) static voidcreatePdf(File svgFile, File pdfFile, ISvgConverterProperties props) static voidcreatePdf(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps) Converts SVG stored in aFileto a PDFFile, using specificISvgConverterPropertiesandWriterProperties.static voidcreatePdf(InputStream svgStream, OutputStream pdfDest) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic voidcreatePdf(InputStream svgStream, OutputStream pdfDest, WriterProperties writerProps) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic voidcreatePdf(InputStream svgStream, OutputStream pdfDest, ISvgConverterProperties props) Create a single page pdf containing the SVG on its page using the default processing and drawing logicstatic voidcreatePdf(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 voiddrawOnCanvas(InputStream stream, PdfCanvas canvas) Draws a Stream containing valid SVG to a pre-made canvas object.static voiddrawOnCanvas(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 voiddrawOnCanvas(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 voiddrawOnCanvas(InputStream stream, PdfCanvas canvas, ISvgConverterProperties props) Draws a Stream containing valid SVG to a pre-made canvas object.static voiddrawOnCanvas(String content, PdfCanvas canvas) Draws a String containing valid SVG to a pre-made canvas object.static voiddrawOnCanvas(String content, PdfCanvas canvas, float x, float y) Draws a String containing valid SVG to a pre-made canvas object.static voiddrawOnCanvas(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 voiddrawOnCanvas(String content, PdfCanvas canvas, ISvgConverterProperties props) Draws a String containing valid SVG to a pre-made canvas object.static voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnDocument(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 voiddrawOnPage(InputStream stream, PdfPage page) Draws a Stream containing valid SVG to a given page at coordinate 0,0.static voiddrawOnPage(InputStream stream, PdfPage page, float x, float y) Draws a Stream containing valid SVG to a given page, at a given location.static voiddrawOnPage(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 voiddrawOnPage(InputStream stream, PdfPage page, ISvgConverterProperties props) Draws a Stream containing valid SVG to a given page at a given location.static voiddrawOnPage(String content, PdfPage page) Draws a String containing valid SVG to a given page at the origin of the page.static voiddrawOnPage(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 voiddrawOnPage(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 voiddrawOnPage(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) Deprecated.static INodeparse(InputStream stream) Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.static INodeparse(InputStream stream, ISvgConverterProperties props) Parse a Stream containing valid SVG into an XML DOM node, using the default JSoup XML parser.static INodeParse a String containing valid SVG into an XML DOM node, using the default JSoup XML parser.static ISvgProcessorResultparseAndProcess(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 ISvgProcessorResultparseAndProcess(InputStream svgStream, ISvgConverterProperties props) Parse and process an Inputstream containing an SVG, using the default Svg processor (DefaultSvgProcessor)static ISvgProcessorResultprocess(INode root, ISvgConverterProperties props) Use the default implementation ofISvgProcessorto convert an XML DOM tree to a node renderer tree.
-
Field Details
-
SVG_DEFAULT_ROLE
- See Also:
-
-
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- thePdfDocumentinstance 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- thePdfDocumentinstance 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- thePdfDocumentinstance 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- thePdfDocumentinstance 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance 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- thePdfPageinstance 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- thePdfPageinstance 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- thePdfPageinstance 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- thePdfPageinstance 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- theStreamobject containing valid SVG content -
page- thePdfPageinstance 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- theStreamobject containing valid SVG content -
page- thePdfPageinstance 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- theStreamobject containing valid SVG content -
page- thePdfPageinstance 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- theStreamobject containing valid SVG content -
page- thePdfPageinstance 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- thePdfCanvasinstance 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- thePdfCanvasinstance 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- thePdfCanvasinstance 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- thePdfCanvasinstance 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- theStreamobject containing valid SVG content -
canvas- thePdfCanvasinstance 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- theStreamobject containing valid SVG content -
canvas- thePdfCanvasinstance 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- theStreamobject containing valid SVG content -
canvas- thePdfCanvasinstance 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- theStreamobject containing valid SVG content -
canvas- thePdfCanvasinstance 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- theFilecontaining the source SVG -
pdfFile- theFilecontaining 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- theFilecontaining the source SVG -
pdfFile- theFilecontaining the resulting PDF -
props- aISvgConverterPropertiesan 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- theFilecontaining the source SVG -
pdfFile- theFilecontaining the resulting PDF -
writerProps- theWriterPropertiesfor 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 aFileto a PDFFile, using specificISvgConverterPropertiesandWriterProperties.- Parameters:
-
svgFile- theFilecontaining the source SVG -
pdfFile- theFilecontaining the resulting PDF -
props- aISvgConverterPropertiesan instance for extra properties to customize the behavior -
writerProps- aWriterPropertiesfor 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-Streamcontaining 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-Streamcontaining 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-Streamcontaining the SVG -
pdfDest- PDF destination outputStream -
props-ISvgConverterPropertiesan 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-Streamcontaining the SVG -
pdfDest- PDF destination outputStream -
props-ISvgConverterPropertiesan instance for extra properties to customize the behavior -
writerProps-WriterPropertiesfor the pdf document - Throws:
-
IOException- when the one of the streams cannot be read correctly
-
convertToXObject
Converts a String containing valid SVG content to anXObjectthat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- thePdfDocumentinstance to draw on - Returns:
-
a
XObjectcontaining 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 anXObjectthat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- thePdfDocumentinstance to draw on -
props-ISvgConverterPropertiesan instance for extra properties to customize the behavior - Returns:
-
a
XObjectcontaining 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 anXObjectthat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance to draw on -
props-ISvgConverterPropertiesan instance for extra properties to customize the behavior - Returns:
-
a
XObjectcontaining 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 anXObjectthat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance to draw on - Returns:
-
a
XObjectcontaining 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 anXObjectthat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance to draw on - Returns:
-
a
Imagecontaining 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 animagethat can then be used on the passedPdfDocument. This method does NOT manipulate thePdfDocumentin 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
PdfDocumentinstances, 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- theStreamcontaining valid SVG content -
document- thePdfDocumentinstance to draw on -
props-ISvgConverterPropertiesan instance for extra properties to customize the behavior - Returns:
-
a
Imagecontaining 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
PdfDocumentinstances, 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- theISvgNodeRendererinstance that contains the renderer tree -
document- the document that the returnedXObjectcan be drawn on (on any given page coordinates) - Returns:
-
an
XObjectcontaining 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-Streamcontaining the SVG to parse and process - Returns:
-
ISvgProcessorResultcontaining 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-Streamcontaining the SVG to parse and process -
props-ISvgConverterPropertiesan instance for extra properties to customize the behavior - Returns:
-
ISvgProcessorResultcontaining the root renderer and metadata of the svg
-
process
Use the default implementation ofISvgProcessorto 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-ISvgConverterPropertiesan 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- theStreamcontaining 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 thepropsparameter.- Parameters:
-
stream- theStreamcontaining valid SVG content -
props-ISvgConverterPropertiesan 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
Deprecated.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 wellDeprecated in favour of
SvgCssUtils.extractWidthAndHeight(ISvgNodeRenderer, float, SvgDrawContext)- Parameters:
-
topSvgRenderer- theISvgNodeRendererinstance that contains the renderer tree - Returns:
- float[2], width is in position 0, height in position 1
-