Java extracts text content of SmartArt shapes in PowerPoint

In the previous article, I introduced How to add SmartArt shapes to PowerPoint, but today I will extract the text content of SmartArt shapes with a Java program. I will show you how. (Library: Free Spire.Presentation for Java)

** Import JAR package ** ** Method 1: ** After downloading and unzipping Free Spire.Presentation for Java, in the lib folder Import the Spire.Presentation.jar package into your Java application as a dependency.

** Method 2: ** After installing the JAR package directly from the Maven repository, configure the pom.xml file as follows:

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>

** Java sample code **

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("SmartArt.pptx");

        //Create a new txt document
        String result = "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 the text extracted from SmartArt." + "\r\n");

        //Loop through all the slides and get the SmartArt shape
        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 the text that was in SmartArt
                    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();

    }
}

75778150-D752-43a0-A3CB-3837AFC5BB03.png

Recommended Posts

Java extracts text content of SmartArt shapes in PowerPoint
Create hyperlinks in Java PowerPoint
Insert footer in Java Powerpoint
Implementation of gzip in java
Implementation of tri-tree in Java
Easily read text files in Java (Java 11 & Java 7)
Java to extract PDF text content
Java adds SmartArt graphics to PowerPoint
List of members added in Java 9
List of types added in Java 9
Java draws shapes in PDF documents
Implementation of like function in Java
[Java] I participated in ABC-188 of Atcorder.
Get the result of POST in Java
The story of writing Java in Emacs
Role of JSP in Web application [Java]
Discrimination of Enums in Java 7 and above
The story of low-level string comparison in Java
[Java] Handling of JavaBeans in the method chain
The story of making ordinary Othello in Java
About the idea of anonymous classes in Java
The story of learning Java in the first programming
Measure the size of a folder in Java
[Java] Use of final in local variable declaration
Feel the passage of time even in Java
Text extraction in Java from PDF with pdfbox-2.0.8
Display text as ASCII art in Java (jfiglet)
Basics of threads and Callable in Java [Beginner]
Java adds a text box to PowerPoint slides
A quick review of Java learned in class
Method name of method chain in Java Builder + α
Change paragraph text color in Java Word documents
Import files of the same hierarchy in Java
Why use setters/getters instead of public/private in Java
Java enables extraction of PDF text and images
[Java] Integer information of characters in a text file acquired by the read () method