News Category

Add Shadow Effects to Shapes in PowerPoint in Java

2020-09-22 06:15:09 Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to add shadow effects to shapes in PowerPoint by using Spire.Presentation for Java. In addition to the PresetShadowEffect shown in this article, you can also add InnerShadowEffect, OuterShadowEffect and SoftEdgeEffect, etc.

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;

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

        //Create a Presentation instance
        Presentation ppt = new Presentation();

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

        //Add a shape to the slide.
        Rectangle2D rect = new Rectangle2D.Float(120, 100, 150, 300);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);

        //Fill the shape with a picture
        shape.getFill().setFillType(FillFormatType.PICTURE);
        shape.getFill().getPictureFill().getPicture().setUrl("https://cdn.e-iceblue.com/C:\\Users\\Administrator\\Desktop\\img.png");
        shape.getLine().setFillType(FillFormatType.NONE);
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);

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

        //Apply the shadow effect to shape
        shape.getEffectDag().setPresetShadowEffect(presetShadow);

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

Add Shadow Effects to Shapes in PowerPoint in Java

Additional Info

  • tutorial_title:
Last modified on Thursday, 02 September 2021 05:56