com.aspose.words

Class ShapeRenderer

public class ShapeRenderer 
extends NodeRendererBase

Provides methods to render an individual Shape or GroupShape to a raster or vector image or to a Graphics object.

Constructor Summary
ShapeRenderer(ShapeBase shape)
Initializes a new instance of this class.
 
Property Getters/Setters Summary
java.awt.geom.Rectangle2D.FloatgetBoundsInPoints()
Gets the actual bounds of the shape in points.
java.awt.geom.Rectangle2D.FloatgetOpaqueBoundsInPoints()
Gets the opaque bounds of the shape in points.
java.awt.DimensiongetSizeInPoints()
Gets the actual size of the shape in points.
 
Method Summary
java.awt.RectanglegetBoundsInPixels(float scale, float dpi)
Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
java.awt.RectanglegetBoundsInPixels(float scale, float horizontalDpi, float verticalDpi)
Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
java.awt.RectanglegetOpaqueBoundsInPixels(float scale, float dpi)
Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
java.awt.RectanglegetOpaqueBoundsInPixels(float scale, float horizontalDpi, float verticalDpi)
Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
java.awt.DimensiongetSizeInPixels(float scale, float dpi)
Calculates the size of the shape in pixels for a specified zoom factor and resolution.
java.awt.DimensiongetSizeInPixels(float scale, float horizontalDpi, float verticalDpi)
Calculates the size of the shape in pixels for a specified zoom factor and resolution.
java.awt.geom.Point2D.FloatrenderToScale(java.awt.Graphics2D graphics, float x, float y, float scale)
Renders the shape into a java.awt.Graphics2D object to a specified scale.
floatrenderToSize(java.awt.Graphics2D graphics, float x, float y, float width, float height)
Renders the shape into a java.awt.Graphics2D object to a specified size.
voidsave(java.io.OutputStream stream, ImageSaveOptions saveOptions)
Renders the shape into an image and saves into a stream.
voidsave(java.lang.String fileName, ImageSaveOptions saveOptions)
Renders the shape into an image and saves into a file.
 

    • Constructor Detail

      • ShapeRenderer

        public ShapeRenderer(ShapeBase shape)
                      throws java.lang.Exception
        Initializes a new instance of this class.
        Parameters:
        shape - The DrawinML shape object that you want to render.
    • Property Getters/Setters Detail

      • getBoundsInPoints

        public java.awt.geom.Rectangle2D.Float getBoundsInPoints()
        
        Gets the actual bounds of the shape in points.

        This property returns the actual (as rendered on the page) bounding box of the shape. The bounds takes into account shape rotation (if any).

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getOpaqueBoundsInPoints

        public java.awt.geom.Rectangle2D.Float getOpaqueBoundsInPoints()
        
        Gets the opaque bounds of the shape in points.

        This property returns the opaque (i.e. transparent parts of the shape are ignored) bounding box of the shape. The bounds takes the shape rotation into account.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getSizeInPoints

        public java.awt.Dimension getSizeInPoints()
        
        Gets the actual size of the shape in points.

        This property returns the size of the actual (as rendered on the page) bounding box of the shape. The size takes into account shape rotation (if any).

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
    • Method Detail

      • getBoundsInPixels

        public java.awt.Rectangle getBoundsInPixels(float scale, float dpi)
        Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.

        This method converts BoundsInPoints into rectangle in pixels.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        dpi - The resolution (horizontal and vertical) to convert from points to pixels (dots per inch).
        Returns:
        The actual (as rendered on the page) bounding box of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getBoundsInPixels

        public java.awt.Rectangle getBoundsInPixels(float scale, float horizontalDpi, float verticalDpi)
        Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.

        This method converts BoundsInPoints into rectangle in pixels.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        horizontalDpi - The horizontal resolution to convert from points to pixels (dots per inch).
        verticalDpi - The vertical resolution to convert from points to pixels (dots per inch).
        Returns:
        The actual (as rendered on the page) bounding box of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getOpaqueBoundsInPixels

        public java.awt.Rectangle getOpaqueBoundsInPixels(float scale, float dpi)
                                         throws java.lang.Exception
        Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.

        This method converts OpaqueBoundsInPoints into rectangle in pixels and it is useful when you want to create a bitmap for rendering the shape with only opaque part of the shape.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        dpi - The resolution to convert from points to pixels (dots per inch).
        Returns:
        The opaque rectangle of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getOpaqueBoundsInPixels

        public java.awt.Rectangle getOpaqueBoundsInPixels(float scale, float horizontalDpi, float verticalDpi)
                                         throws java.lang.Exception
        Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.

        This method converts OpaqueBoundsInPoints into rectangle in pixels and it is useful when you want to create a bitmap for rendering the shape with only opaque part of the shape.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        horizontalDpi - The horizontal resolution to convert from points to pixels (dots per inch).
        verticalDpi - The vertical resolution to convert from points to pixels (dots per inch).
        Returns:
        The opaque rectangle of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getSizeInPixels

        public java.awt.Dimension getSizeInPixels(float scale, float dpi)
        Calculates the size of the shape in pixels for a specified zoom factor and resolution.

        This method converts SizeInPoints into size in pixels and it is useful when you want to create a bitmap for rendering the shape neatly onto the bitmap.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        dpi - The resolution (horizontal and vertical) to convert from points to pixels (dots per inch).
        Returns:
        The size of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • getSizeInPixels

        public java.awt.Dimension getSizeInPixels(float scale, float horizontalDpi, float verticalDpi)
        Calculates the size of the shape in pixels for a specified zoom factor and resolution.

        This method converts SizeInPoints into size in pixels and it is useful when you want to create a bitmap for rendering the shape neatly onto the bitmap.

        Parameters:
        scale - The zoom factor (1.0 is 100%).
        horizontalDpi - The horizontal resolution to convert from points to pixels (dots per inch).
        verticalDpi - The vertical resolution to convert from points to pixels (dots per inch).
        Returns:
        The size of the shape in pixels.

        Example:

        Shows how to measure and scale shapes.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath);
        
        Assert.assertEquals(119.0f, renderer.getBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(13.0f, renderer.getBoundsInPoints().getHeight(), 0.1f);
        
        // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
        Assert.assertEquals(119.0f, renderer.getOpaqueBoundsInPoints().getWidth(), 0.2f);
        Assert.assertEquals(14.2f, renderer.getOpaqueBoundsInPoints().getHeight(), 0.1f);
        
        // Get the shape size in pixels, with linear scaling to a specific DPI.
        Rectangle bounds = renderer.getBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        // Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
        bounds = renderer.getBoundsInPixels(1.0f, 96.0f, 150.0f);
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(28.0, bounds.getHeight());
        
        // The opaque bounds may vary here also.
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(18.0, bounds.getHeight());
        
        bounds = renderer.getOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
        
        Assert.assertEquals(159.0, bounds.getWidth());
        Assert.assertEquals(30.0, bounds.getHeight());
      • renderToScale

        public java.awt.geom.Point2D.Float renderToScale(java.awt.Graphics2D graphics, float x, float y, float scale)
                           throws java.lang.Exception
        Renders the shape into a java.awt.Graphics2D object to a specified scale.
        Parameters:
        graphics - The object where to render to.
        x - The X coordinate (in world units) of the top left corner of the rendered shape.
        y - The Y coordinate (in world units) of the top left corner of the rendered shape.
        scale - The scale for rendering the shape (1.0 is 100%).
        Returns:
        The width and height (in world units) of the rendered shape.
      • renderToSize

        public float renderToSize(java.awt.Graphics2D graphics, float x, float y, float width, float height)
                          throws java.lang.Exception
        Renders the shape into a java.awt.Graphics2D object to a specified size.
        Parameters:
        graphics - The object where to render to.
        x - The X coordinate (in world units) of the top left corner of the rendered shape.
        y - The Y coordinate (in world units) of the top left corner of the rendered shape.
        width - The maximum width (in world units) that can be occupied by the rendered shape.
        height - The maximum height (in world units) that can be occupied by the rendered shape.
        Returns:
        The scale that was automatically calculated for the rendered shape to fit the specified size.
      • save

        public void save(java.io.OutputStream stream, ImageSaveOptions saveOptions)
                 throws java.lang.Exception
        Renders the shape into an image and saves into a stream.
        Parameters:
        stream - The stream where to save the image of the shape.
        saveOptions - Specifies the options that control how the shape is rendered and saved. Can be null. If this is null, the image will be saved in the PNG format.

        Example:

        Shows how to use a shape renderer to export shapes to files in the local file system.
        Document doc = new Document(getMyDir() + "Various shapes.docx");
        NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
        
        Assert.assertEquals(7, shapes.getCount());
        
        // There are 7 shapes in the document, including one group shape with 2 child shapes.
        // We will render every shape to an image file in the local file system
        // while ignoring the group shapes since they have no appearance.
        // This will produce 6 image files.
        for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
            ShapeRenderer renderer = shape.getShapeRenderer();
            ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
            renderer.save(getArtifactsDir() + MessageFormat.format("Shape.RenderAllShapes.{0}.png", shape.getName()), options);
        }
      • save

        public void save(java.lang.String fileName, ImageSaveOptions saveOptions)
                 throws java.lang.Exception
        Renders the shape into an image and saves into a file.
        Parameters:
        fileName - The name for the image file. If a file with the specified name already exists, the existing file is overwritten.
        saveOptions - Specifies the options that control how the shape is rendered and saved. Can be null.

        Example:

        Shows how to render an Office Math object into an image file in the local file system.
        Document doc = new Document(getMyDir() + "Office math.docx");
        
        OfficeMath math = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
        
        // Create an "ImageSaveOptions" object to pass to the node renderer's "Save" method to modify
        // how it renders the OfficeMath node into an image.
        ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
        
        // Set the "Scale" property to 5 to render the object to five times its original size.
        saveOptions.setScale(5f);
        
        math.getMathRenderer().save(getArtifactsDir() + "Shape.RenderOfficeMath.png", saveOptions);