SmartArt graphics are a visual representation of textual information with powerful typesetting capabilities. This article shows you how to use Java code to create SmartArt graphics on your slides and customize their layout.
** Tools used: ** Free Spire.Presentation for Java (free version)
** Installation Method 1: ** Download and unzip the Free Spire.Presentation for Java package, Then import the Spire.Presentation.jar package into your Java application from the lib folder.
** Installation Method 2: ** Install and import through Maven Warehouse. See the link for detailed operating instructions: https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html
** Java code example **
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.diagrams.*;
public class AddSmartArt {
    public static void main(String[] args) throws Exception {
        //Create a PowerPoint document
        Presentation presentation = new Presentation();
        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);
        //Organizational diagram on slide'Organization Chart'To create
        ISmartArt smartArt = slide.getShapes().appendSmartArt(60, 60, 500, 300, SmartArtLayoutType.ORGANIZATION_CHART);
        //Set the style and color of SmartArt
        smartArt.setStyle(SmartArtStyleType.MODERATE_EFFECT);
        smartArt.setColorStyle(SmartArtColorType.DARK_2_OUTLINE);
        //Delete the default node (SmartArt graphic)
        for (Object a : smartArt.getNodes()) {
            smartArt.getNodes().removeNode(0);
        }
        //Add a parent node
        ISmartArtNode node1 = smartArt.getNodes().addNode();
        //Add 4 child nodes under the parent node
        ISmartArtNode node1_1 = node1.getChildNodes().addNode();
        ISmartArtNode node1_2 = node1.getChildNodes().addNode();
        ISmartArtNode node1_3 = node1.getChildNodes().addNode();
        ISmartArtNode node1_4 = node1.getChildNodes().addNode();
        //Set the text and text size of the node
        node1.getTextFrame().setText("head office");
        node1.getTextFrame().getTextRange().setFontHeight(14f);
        node1_1.getTextFrame().setText("Investment Management Department");
        node1_1.getTextFrame().getTextRange().setFontHeight(12f);
        node1_2.getTextFrame().setText("Finance Department");
        node1_2.getTextFrame().getTextRange().setFontHeight(12f);
        node1_3.getTextFrame().setText("Sales department");
        node1_3.getTextFrame().getTextRange().setFontHeight(12f);
        node1_4.getTextFrame().setText("Engineering Department");
        node1_4.getTextFrame().getTextRange().setFontHeight(12f);
        //Save the document
        presentation.saveToFile("SmartArt.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}
** Add SmartArt effect: **

Recommended Posts