Create a SmartArt in PowerPoint in Java

SmartArt is a useful feature in Microsoft PowerPoint that allows to convert your textual data into predefined graphics. This article demonstrates how to create a SmartArt and custom the layout using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.diagrams.*;

public class SmartArt {

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

        //create a PowerPoint file
        Presentation presentation = new Presentation();
        
        //get the first slide
        ISlide slide = presentation.getSlides().get(0);
        
        //insert a Radial Cycle smartart
        ISmartArt smartArt = slide.getShapes().appendSmartArt(60, 60, 200, 200, SmartArtLayoutType.RADIAL_CYCLE);

        //set the style of the smartart
        smartArt.setStyle(SmartArtStyleType.MODERATE_EFFECT);

        //set the color of the smartart
        smartArt.setColorStyle(SmartArtColorType.DARK_2_OUTLINE);

        //remove all default nodes
        for (Object a : smartArt.getNodes()) {
            smartArt.getNodes().removeNode(0);
        }

        //add a parent node 
        ISmartArtNode node1 = smartArt.getNodes().addNode();
      
        //add three child nodes 
        ISmartArtNode node1_1 = node1.getChildNodes().addNode();
        ISmartArtNode node1_2 = node1.getChildNodes().addNode();
        ISmartArtNode node1_3 = node1.getChildNodes().addNode();
     
        //add text to each node and set the font size
        node1.getTextFrame().setText("My Cool\nSmartArt");
        node1.getTextFrame().getTextRange().setFontHeight(14f);
        node1_1.getTextFrame().setText("Text #1");
        node1_1.getTextFrame().getTextRange().setFontHeight(12f);
        node1_2.getTextFrame().setText("Text #2");
        node1_2.getTextFrame().getTextRange().setFontHeight(12f);
        node1_3.getTextFrame().setText("Text #3");
        node1_3.getTextFrame().getTextRange().setFontHeight(12f);

        //save the file
        presentation.saveToFile("output/SmartArt.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}

Create a SmartArt in PowerPoint in Java