Java adds SmartArt graphics to PowerPoint

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: ** smartart.png

Recommended Posts

Java adds SmartArt graphics to PowerPoint
Java adds a text box to PowerPoint slides
Convert Java Powerpoint to XPS
Java adds table to PDF
Java adds hyperlinks to Word documents
Java adds form fields to PDF
Add / remove watermark to Java PowerPoint
[Java] Introduction to Java
Introduction to java
Java adds page numbers to existing PDF documents
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Java extracts text content of SmartArt shapes in PowerPoint
[Java] Connect to MySQL
Kotlin's improvements to Java
From Java to Ruby !!
Introduction to java command
[Java] How to use Map
How to lower java version
Migration from Cobol to JAVA
[Java] How to use Map
How to uninstall Java 8 (Mac)
Java to play with Function
Java --How to make JTable
How to use java Optional
New features from Java7 to Java8
How to minimize Java images
How to write java comments
Create hyperlinks in Java PowerPoint
How to use java class
[Java] How to use Optional ②
Connect from Java to PostgreSQL
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] Introduction to lambda expressions
[Java] How to use string.format
Shell to kill Java process
How to use Java Map
Insert footer in Java Powerpoint
How to set Java constants
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static
How to use Java variables
[Java] Introduction to Stream API
Java8 to start now ~ Optional ~
How to convert Java radix
[Java] Convert ArrayList to array
Java thread to understand loosely
[Java] How to implement multithreading
[Java] How to use Optional ①
From Ineffective Java to Effective Java
How to initialize Java array
[Introduction to rock-paper-scissors games] Java
Input to the Java console