Skip to main content

Read and Modify Presentation Document Properties

  • 3 minutes to read

Document properties are metadata fields stored in a presentation file. The DevExpress Presentation API allows you to read and modify both built-in and custom document properties.

Call the Presentation.getDocumentProperties() method to get a DocumentProperties object that contains all metadata fields.

Built-In Document Properties

Built-in document properties are standard metadata (such as author, category, title, and company). The API sets or updates some properties automatically when you create or save a presentation. Other properties are user-defined.

Method Automatically Updated Read Only
getApplication() No (the API sets the value when you create a presentation) No
getAuthor() No No
getCategory() No No
getCompany() No No
getContentStatus() No No
getCreated() Yes No
getDescription() No No
getDocumentRevision() No No
getDocumentVersion() No No
getHiddenSlides() Yes Yes
getKeywords() No No
getLastModifiedBy() Yes (the API clears the value when you save the presentation) No
getModified() Yes No
getNotes() Yes Yes
getPresentationFormat() Yes Yes
getPrinted() No No
getSecurity() No Yes
getSlides() Yes Yes
getSubject() No No
getTitle() No No
getVersion() No (the API sets the value when you create a presentation) No

Modify Built-In Document Properties

Call setter methods of the DocumentProperties object to modify writable built-in properties.

The following code snippet specifies built-in document properties of a presentation and saves the presentation to a file:

import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.presentation.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Presentation presentation = new Presentation()) {
            DocumentProperties documentProperties = presentation.getDocumentProperties();
            documentProperties.setAuthor("Jane Doe");
            documentProperties.setTitle("Innovating for the Future: Trends in Sustainable Technology");
            documentProperties.setCompany("GreenTech Solutions Inc.");
            documentProperties.setKeywords("Sustainability, Green Technology, Innovation");

            Files.createDirectories(Path.of("output"));
            try (OutputStream output = Files.newOutputStream(Path.of("output", "Document.pptx"))) {
                presentation.save(output);
            }
        }
    }
}

Create Custom Document Properties

Custom document properties are user-defined metadata. The DocumentProperties.getCustomProperties() method returns an IDocumentCustomPropertyDictionary map of custom properties. Call the put method of the map to add a custom property.

Custom document properties support the following data types:

  • String
  • boolean
  • Instant (date and time)
  • BigDecimal
  • double
  • int

The following code snippet adds custom properties to the presentation metadata and saves the presentation to a file:

import java.io.*;
import java.math.BigDecimal;
import java.nio.file.*;
import java.time.Instant;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Presentation presentation = new Presentation()) {
            IDocumentCustomPropertyDictionary customProperties =
                    presentation.getDocumentProperties().getCustomProperties();

            // Add custom properties to the dictionary.
            customProperties.put("Project", new DocumentCustomProperty("Apollo"));
            customProperties.put("Approved", new DocumentCustomProperty(true));
            customProperties.put("Review Date", new DocumentCustomProperty(Instant.now()));
            customProperties.put("Revision Count", new DocumentCustomProperty(5));
            customProperties.put("Completion", new DocumentCustomProperty(0.75));
            customProperties.put("Budget", new DocumentCustomProperty(new BigDecimal("12500.50")));

            Files.createDirectories(Path.of("output"));
            try (OutputStream output = Files.newOutputStream(Path.of("output", "Document.pptx"))) {
                presentation.save(output);
            }
        }
    }
}