In presentations, SmartArt is used to present the information in visual form. Often, the presenters use SmartArt to make the simple text more appealing. Moreover, it is also used to create flow diagrams, processes, relationships between different entities, etc. In this article, you will learn how to create SmartArt in PowerPoint presentations programmatically using Java.
- Java API to Create SmartArt in PowerPoint
- Create a SmartArt Shape in PowerPoint
- Access a SmartArt Shape in PowerPoint
- Change SmartArt Shape’s Style
Java API to Create SmartArt in PowerPoint
In order to manipulate SmartArt in PowerPoint presentations, we will use Aspose.Slides for Java. It is a powerful library that allows the creation and manipulation of PowerPoint and OpenOffice presentations from scratch. You can either install the API using the following Maven configurations or download its JAR.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>21.8</version>
<classifier>jdk16</classifier>
</dependency>
Create a SmartArt Shape in PowerPoint using Java
Aspose.Slides for Java makes it quite easy to create the SmartArt shapes in the presentations. Let’s create a simple SmartArt shape from scratch in a PowerPoint presentation using Java.
- First, create a new presentation or load an existing one using Presentation class.
- Get reference of the desired slide into an ISlide object.
- Create a SmartArt using ISlide.getShapes().addSmartArt() method.
- Finally, save the updated presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to create a SmartArt shape in a PowerPoint presentation.
The following screenshot shows the output of the above code sample.
Access a SmartArt Shape in PowerPoint Presentations
You can also access the SmartArt shapes in the existing PowerPoint presentations and update them dynamically. The following are the steps to access the SmartArt shapes in PowerPoint presentations using Java.
- First, create a new presentation or load an existing one using Presentation class.
- Then, get reference of the desired slide into an ISlide object.
- Loop through the shapes in the slide using ISlide.getShapes() collection.
- If the shape is of type ISmartArt, then get its reference into an ISmartArt object.
- If required, filter the SmartArt shapes of a specific layout using ISmartArt.getLayout().
The following code sample shows how to access SmartArt shapes in PowerPoint presentations.
Change SmartArt Shape’s Style using Java
You can also modify the styles of the SmartArt shapes using Aspose.Slides. The following steps demonstrate how to access the SmartArt shapes in a PowerPoint presentation and change their styles using Java.
- First, create a new presentation or load an existing one using Presentation class.
- Then, get reference of the desired slide into an ISlide object.
- Loop through the shapes in the slide using ISlide.getShapes() collection.
- If the shape is of type ISmartArt, then get its reference into an ISmartArt object.
- Change the desired style, i.e. ColorStyle, QuickStyle, etc.
- Finally, save the updated presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to change the style of the SmartArt shapes in PowerPoint presentations.
Get a Free API License
Use Aspose.Slides for Java without evaluation limitations by getting a free temporary license.
Conclusion
In this article, you have learned how to create SmartArt in PowerPoint presentations using Java. Moreover, you have seen how to access the SmartArt shapes and change their styles programmatically. You can explore the documentation to learn more about Aspose.Slides for Java. In addition, you can ask your questions via our forum.