Smartart

Smartart (2)

This article will introduce how to extract text from SmartArt in PowerPoint in Java applications.

Firstly view the sample document:

Java extract text from SmartArt in PowerPoint

import com.spire.presentation.Presentation;
import com.spire.presentation.diagrams.ISmartArt;
import java.io.*;

public class extractTextFromSmartArt {
    public static void main(String[] args) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Create a new TXT File
        String result = "output/extractTextFromSmartArt.txt";
        File file=new File(result);
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
        FileWriter fw =new FileWriter(file,true);
        BufferedWriter bw =new BufferedWriter(fw);

        bw.write("Below is extracted text from SmartArt:" + "\r\n");

        //Traverse through all the slides of the PPT file and find the SmartArt shapes.
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            for (int j = 0; j < presentation.getSlides().get(i).getShapes().getCount(); j++)
            {
                if (presentation.getSlides().get(i).getShapes().get(j) instanceof ISmartArt)
                {
                    ISmartArt smartArt = (ISmartArt)presentation.getSlides().get(i).getShapes().get(j);

                    //Extract text from SmartArt and append to the StringBuilder object.
                    for (int k = 0; k < smartArt.getNodes().getCount(); k++)
                    {
                        bw.write(smartArt.getNodes().get(k).getTextFrame().getText() + "\r\n");
                    }
                }
            }
        }
        bw.flush();
        bw.close();
        fw.close();

    }
}

Effective screenshot of the extracting Text from SmartArt:

Java extract text from SmartArt in PowerPoint

Wednesday, 09 January 2019 08:00

Create a SmartArt in PowerPoint in Java

Written by support iceblue

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