Document Properties in PowerPoint Java

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 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.

The following code sample shows how to access built-in properties in PowerPoint presentations.

// Load presentation
Presentation pres = new Presentation("Presentation.pptx");
try {
// Create a reference to IDocumentProperties object associated with presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Display the built-in properties
System.out.println("Category : " + dp.getCategory());
System.out.println("Current Status : " + dp.getContentStatus());
System.out.println("Creation Date : " + dp.getCreatedTime());
System.out.println("Author : " + dp.getAuthor());
System.out.println("Description : " + dp.getComments());
System.out.println("KeyWords : " + dp.getKeywords());
System.out.println("Last Modified By : " + dp.getLastSavedBy());
System.out.println("Supervisor : " + dp.getManager());
System.out.println("Modified Date : " + dp.getLastSavedTime());
System.out.println("Presentation Format : " + dp.getPresentationFormat());
System.out.println("Last Print Date : " + dp.getLastPrinted());
System.out.println("Is Shared between producers : " + dp.getSharedDoc());
System.out.println("Subject : " + dp.getSubject());
System.out.println("Title : " + dp.getTitle());
} finally {
if (pres != null) pres.dispose();
}

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.

The following code sample shows how to modify the built-in properties in PowerPoint Presentations.

// Load presentation
Presentation pres = new Presentation("Presentation.pptx");
try {
// Create a reference to IDocumentProperties object associated with Presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Set the built-in properties
dp.setAuthor("Aspose.Slides for Java");
dp.setTitle("Modifying Presentation Properties");
dp.setSubject("Aspose Subject");
dp.setComments("Aspose Description");
dp.setManager("Aspose Manager");
// Save your presentation to a file
pres.save("DocProps.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}

Add Custom Properties in PowerPoint Presentations using Java

The following are the steps to add custom properties in a PowerPoint presentation using Java.

The following code sample shows how to add custom properties in a PowerPoint presentation.

// Load presentation
Presentation pres = new Presentation("Presentation.pptx");
try {
// Get Document Properties
IDocumentProperties dProps = pres.getDocumentProperties();
// Add Custom properties
dProps.set_Item("New Custom", 12);
dProps.set_Item("My Name", "Mudassir");
dProps.set_Item("Custom", 124);
// Get property name at particular index
String getPropertyName = dProps.getCustomPropertyName(2);
// To remove selected property
//dProps.removeCustomProperty(getPropertyName);
// Save presentation
pres.save("CustomDemo.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}

Access Custom Properties in PowerPoint Presentations using Java

The following steps demonstrate how to access the custom properties in a PowerPoint Presentation using Java.

The following code sample shows how to access custom properties in a PowerPoint Presentation.

// Load presentation
Presentation pres = new Presentation("Presentation.pptx");
try {
// Create a reference to DocumentProperties object associated with presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Access and modify custom properties
for (int i = 0; i < dp.getCountOfCustomProperties(); i++) {
// Display names and values of custom properties
System.out.println("Custom Property Name : " + dp.getCustomPropertyName(i));
System.out.println("Custom Property Value : " + dp.get_Item(dp.getCustomPropertyName(i)));
}
// Save your presentation to a file
pres.save("CustomDemoModified.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}

Modify Custom Properties in PowerPoint Presentations using Java

The following are the steps to modify the custom properties in a PowerPoint presentation.

The following code sample shows how to modify a custom property in a PowerPoint presentation.

// Load presentation
Presentation pres = new Presentation("Presentation.pptx");
try {
// Create a reference to DocumentProperties object associated with presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Access and modify custom properties
for (int i = 0; i < dp.getCountOfCustomProperties(); i++) {
// Modify values of custom properties
dp.set_Item(dp.getCustomPropertyName(i), "New Value " + (i + 1));
}
// Save your presentation to a file
pres.save("CustomDemoModified.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}

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.

See Also