Java--How to cast shadows on PowerPoint shapes

By adding a shadow effect to a shape in PowerPoint, you can improve the three-dimensional effect of the shape, realize a more realistic effect, and further enhance the aesthetics of the document. Therefore, this article will show you how to use Free Spire.Presentation for Java to cast shadows on PowerPoint shapes. By the way, in addition to the preset shadow effects, there are inner shadows (InnerShadowEffect), outer shadows (OuterShadowEffect), and contour blur (SoftEdgeEffect).

** Import JAR package ** ** Method 1: ** After downloading and unzipping Free Spire.Presentation for Java, in the lib folder Import the Spire.Presentation.jar package as a dependency into your Java application.

** Method 2: ** After installing the JAR package directly from the Maven repository, configure the pom.xml file as follows:

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>

** Java code example **

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.PictureFillType;
import com.spire.presentation.drawing.PresetShadow;

import java.awt.geom.Rectangle2D;
import java.awt.Color;

public class ShapeShadowEffect {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object.
        Presentation ppt = new Presentation();

        //Get the first slide.
        ISlide slide = ppt.getSlides().get(0);

        //Add a shape.
        Rectangle2D rect = new Rectangle2D.Float(120, 80, 180, 150);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE,rect);

        //Fill the shape with the image.
        shape.getFill().setFillType(FillFormatType.PICTURE);
        shape.getFill().getPictureFill().getPicture().setUrl("C:\\Users\\Administrator\\Desktop\\cow.png ");
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        shape.getLine().setFillType(FillFormatType.NONE);

        //Sets the shadow effect.
        PresetShadow presetShadow = new PresetShadow();
        presetShadow.setPreset(PresetShadowValue.BACK_RIGHT_PERSPECTIVE);
        presetShadow.getColorFormat().setColor(Color.lightGray);

        //Add a shadow to the shape.
        shape.getEffectDag().setPresetShadowEffect(presetShadow);

        //Save the document.
        ppt.saveToFile("ShapeShadow.pptx", FileFormat.PPTX_2013);
    }
}

Execution result: shadow.png

Recommended Posts

Java--How to cast shadows on PowerPoint shapes