Extracting Text from SmartArt in PowerPoint Presentations Using Java

<p>In a previous article we discussed how to add SmartArt graphics in PPT. This article demonstrates how to extract text content from SmartArt shapes using Java, with the help of Free Spire.Presentation for Java.</p> <p>&nbsp;</p> <p><strong>Importing JAR Dependencies</strong></p> <p><strong>Method 1:</strong> Download the Free Spire.Presentation for Java package, unzip it, and add the JAR files inside the lib folder to your project’s build path.</p> <p><strong>Method 2:</strong> Use Maven by adding the following repository and dependency to your pom.xml:</p> <div> <pre>&lt;repositories&gt; &lt;repository&gt; &lt;id&gt;com.e-iceblue&lt;/id&gt; &lt;url&gt;http://repo.e-iceblue.cn/repository/maven-public/&lt;/url&gt; &lt;/repository&gt; &lt;/repositories&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;e-iceblue&lt;/groupId&gt; &lt;artifactId&gt;spire.presentation.free&lt;/artifactId&gt; &lt;version&gt;3.9.0&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt;</pre> </div> <p>&nbsp;</p> <p><strong>Java Code Example</strong></p> <div> <pre>import com.spire.presentation.Presentation; import com.spire.presentation.diagrams.ISmartArt; import java.io.*; public class SmartArtContentExtractor { public static void main(String[] args) throws Exception { Presentation ppt = new Presentation(); ppt.loadFromFile("SmartArt.pptx"); String outputPath = "output/smartart_text.txt"; File outFile = new File(outputPath); if (outFile.exists()) { outFile.delete(); } outFile.createNewFile(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) { writer.write("Extracted SmartArt Text Content:\r\n"); for (int slideIndex = 0; slideIndex < ppt.getSlides().getCount(); slideIndex++) { com.spire.presentation.ISlide slide = ppt.getSlides().get(slideIndex); for (int shapeIndex = 0; shapeIndex < slide.getShapes().getCount(); shapeIndex++) { com.spire.presentation.IShape shape = slide.getShapes().get(shapeIndex); if (shape instanceof ISmartArt) { ISmartArt smartArt = (ISmartArt) shape; for (int nodeIndex = 0; nodeIndex < smartArt.getNodes().getCount(); nodeIndex++) { writer.write(smartArt.getNodes().get(nodeIndex).getTextFrame().getText() + "\r\n"); } } } } } } } </pre> </div> <p>&nbsp;</p> <p><strong>Output:</strong> A text file will be created containing the extracted SmartArt text content.</p>

Tags: java PowerPoint SmartArt TextExtraction Spire.Presentation

Posted on Mon, 11 May 2026 03:50:44 +0000 by clodagh2000