PowerPoint files contain some additional information known as document properties. These properties are used for the identification of the presentations, which include author, title, keywords, subject, etc. In this article, you will learn how to add, access or modify the document properties in PowerPoint files using Java.
- Java API to Access/Modify Properties in PowerPoint Files
- Types of Properties in PowerPoint Presentations
- Access Built-in Properties in PowerPoint Presentations
- Modify Built-in Properties in PowerPoint Presentations
- Add Custom Properties in PowerPoint Presentations
- Access Custom Properties in PowerPoint Presentations
- Modify Custom Properties in PowerPoint Presentations
Java API for Document Properties in PowerPoint Files
To access or modify the document properties in PowerPoint presentations, we will use Aspose.Slides for Java. The API allows you to create and manipulate PowerPoint and OpenOffice documents. It is available as a downloadable JAR as well as on Maven. You can install it using the following Maven configurations.
<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>
Types of Document Properties in PowerPoint Presentations
There are two types of document properties in PowerPoint files: built-in and custom. The former provides general information about the presentations such as title, author, subject, etc. Whereas, the latter is used to add user-defined properties. In the below sections, you will see how to add, access, and modify built-in and custom document properties in PowerPoint presentations.
Access Built-in Properties in PowerPoint Presentations using Java
The following are the steps to access the built-in properties in PowerPoint presentations using Java.
- First, load the PowerPoint presentation using Presentation class.
- Then, access the built-in properties in an IDocumentProperties object using Presentation.getDocumentProperties() method.
- Read each built-in property in the presentation using IDocumentProperties object, such as, IDocumentProperties.getAuthor().
The following code sample shows how to access built-in properties in PowerPoint presentations.
Modify Built-in Properties in PowerPoint Presentations using Java
The following are the steps to modify the values of the built-in properties in PowerPoint presentations using Java.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the built-in properties in an IDocumentProperties object using Presentation.getDocumentProperties() method.
- Modify the desired built-in property in the presentation using IDocumentProperties object, such as, IDocumentProperties.setAuthor().
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to modify the built-in properties in PowerPoint Presentations.
Add Custom Properties in PowerPoint Presentations using Java
The following are the steps to add custom properties in a PowerPoint presentation using Java.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the document properties in an IDocumentProperties object using Presentation.getDocumentProperties() method.
- Add a custom property by defining its key and value, e.g. IDocumentPropertiesd.set_Item(“New Custom”, 12).
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to add custom properties in a PowerPoint presentation.
Access Custom Properties in PowerPoint Presentations using Java
The following steps demonstrate how to access the custom properties in a PowerPoint Presentation using Java.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the document properties in an IDocumentProperties object using Presentation.getDocumentProperties() method.
- Access each custom property using IDocumentProperties.getCustomPropertyName(int index) method in a loop.
The following code sample shows how to access custom properties in a PowerPoint Presentation.
Modify Custom Properties in PowerPoint Presentations using Java
The following are the steps to modify the custom properties in a PowerPoint presentation.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the document properties in an IDocumentProperties object using Presentation.getDocumentProperties() method.
- Access each custom property using IDocumentProperties.getCustomPropertyName(int index) method in a loop.
- Set the value of a property by specifying its key.
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to modify a custom property in a PowerPoint presentation.
Get a Free API License
You can use Aspose.Slides for Java without evaluation limitations by requesting a temporary license.
Online Demo
Try Aspose.Slides based online tool to view and edit document properties in the presentations.
Conclusion
In this article, you have learned how to access and modify document properties in PowerPoint presentations using Java. We have explicitly covered the manipulation of built-in as well as custom document properties in the presentations. In addition, you can visit the documentation to explore other features of Aspose.Slides for Java. Also, you can post your queries to our forum.