Applying Shadow Effects to Shapes in PowerPoint Using Java
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.