Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Applying Shadow Effects to Shapes in PowerPoint Using Java

Notes Jun 16 21
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 PptShadowDemo {

    public static void main(String[] args) throws Exception {
        // Create a new presentation instance
        Presentation presentation = new Presentation();

        // Access the first slide
        ISlide firstSlide = presentation.getSlides().get(0);

        // Draw a rectangle shape
        Rectangle2D bounds = new Rectangle2D.Float(120, 80, 180, 150);
        IAutoShape rectangleShape = firstSlide.getShapes().appendShape(ShapeType.RECTANGLE, bounds);

        // Load and stretch an image into the shape
        rectangleShape.getFill().setFillType(FillFormatType.PICTURE);
        rectangleShape.getFill().getPictureFill().getPicture().setUrl("C:\\Users\\Administrator\\Desktop\\cow.png");
        rectangleShape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        rectangleShape.getLine().setFillType(FillFormatType.NONE);

        // Configure a preset shadow effect
        PresetShadow shadow = new PresetShadow();
        shadow.setPreset(PresetShadowValue.BACK_RIGHT_PERSPECTIVE);
        shadow.getColorFormat().setColor(Color.lightGray);

        // Attach the shadow to the shape
        rectangleShape.getEffectDag().setPresetShadowEffect(shadow);

        // Write the output file
        presentation.saveToFile("ShapeShadow.pptx", FileFormat.PPTX_2013);
    }
}

Shadow effects—including inner, outer, and soft-edge variants—enhance the depth and visual appeal of shapes. The libray must be available in the project claspsath. With Maven, reference it as follows:

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <url>http://repo.e-iceblue.cn/repository/maven-public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>

After execution, the generated PowerPoint file displays the image-filled rectangle with a perspective shadow cast behind it.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.