News Category

Apply a Shadow Effect to Text in PowerPoint in Java

2021-02-22 07:16:29 Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to apply a shadow effect to the text in a PowerPoint slide using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.OuterShadowEffect;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class SetShadowEffect {

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

        //Create a Presentation object
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

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

        //Add a rectangle to slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(50,80,500,100));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getLine().setFillType(FillFormatType.NONE);

        //Set text of the shape
        shape.appendTextFrame("Text shading on slide");

        //Set font style
        shape.getTextFrame().getTextRange().setFontHeight(38f);
        shape.getTextFrame().getTextRange().setLatinFont(new TextFont("Arial Black"));
        shape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        shape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Create a OuterShadowEffect object
        OuterShadowEffect outerShadow= new OuterShadowEffect();

        //Set the shadow effect
        outerShadow.setBlurRadius(0);
        outerShadow.setDirection(50);
        outerShadow.setDistance(10);
        outerShadow.getColorFormat().setColor(Color.orange);

        //Apply shadow effect to text
        shape.getTextFrame().getTextRange().getEffectDag().setOuterShadowEffect(outerShadow);

        //Save to file
        presentation.saveToFile("output/AddShadow.pptx", FileFormat.PPTX_2013);
    }
}

Apply a Shadow Effect to Text in PowerPoint in Java

Additional Info

  • tutorial_title:
Last modified on Thursday, 02 September 2021 06:00