Manage Presentation Properties in PHP
Introduction
Aspose.Slides for PHP via Java supports built-in and custom document properties. Use these properties to read and update presentation metadata, such as the author, title, and user-defined values.
Aspose.Slides allows you to work with presentation document properties through the DocumentProperties class. An instance of this class is returned by Presentation::getDocumentProperties. The following examples show how to read, modify, and manage these properties. They assume that PHP/Java Bridge and the Aspose.Slides PHP wrapper are initialized.
Note
Aspose.Slides manages the application and producer metadata when saving presentations; these fields identify the software that created the output.Manage Presentation Properties
Document properties store descriptive information alongside presentation content. They fall into two categories:
- Built-in properties contain standard metadata, such as the title, author, and document statistics.
- Custom properties store user-defined name/value pairs.
Aspose.Slides for PHP via Java provides access to both categories. In PowerPoint, select File → Info → Properties → Advanced Properties to inspect document metadata. The dialog groups information into tabs such as Summary, Statistics, Contents, and Custom. Use the Custom tab to manage user-defined properties.
Read Public Properties from an Encrypted Presentation
An opening password normally protects both presentation content and document properties. When a presentation is encrypted after calling ProtectionManager::setEncryptDocumentProperties with false, its document properties remain public. An application can then call LoadOptions::setOnlyLoadDocumentProperties with true and read the public metadata without supplying the opening password.
LoadOptions::setOnlyLoadDocumentProperties controls what Aspose.Slides loads; it does not decrypt anything. If the properties were included in encryption, loading them without the password fails. If the presentation is not encrypted, the option is ignored and the complete presentation is loaded.
The example requires an encrypted presentation whose document properties were left public. It verifies the loading mode through ProtectionManager::isOnlyDocumentPropertiesLoaded and then reads built-in properties through Presentation::getDocumentProperties:
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;
$loadOptions = new LoadOptions();
$loadOptions->setOnlyLoadDocumentProperties(true);
$presentation = new Presentation("public-properties-encrypted.pptx", $loadOptions);
try {
if (java_values($presentation->getProtectionManager()->isOnlyDocumentPropertiesLoaded())) {
$documentProperties = $presentation->getDocumentProperties();
echo("Author: " . $documentProperties->getAuthor() . "\n");
echo("Title: " . $documentProperties->getTitle() . "\n");
echo("Keywords: " . $documentProperties->getKeywords() . "\n");
} else {
echo("The presentation was not loaded in document-properties-only mode." . "\n");
}
} finally {
$presentation->dispose();
}
In this mode, slide content is not loaded. Slides, masters, layouts, shapes, media, and other presentation objects are unavailable. Applications should always check ProtectionManager::isOnlyDocumentPropertiesLoaded before performing an operation that requires the complete presentation object model.
Warning
Public metadata may expose author names, titles, subjects, keywords, company information, comments, and custom values. Encrypt sensitive properties together with the presentation. Leave them public only when indexing, classification, search, or document-management systems have a specific requirement to access them without a password.Update Properties of an Encrypted Presentation
For an encrypted PPTX file, a presentation loaded after calling LoadOptions::setOnlyLoadDocumentProperties with true is intended for reading public metadata. Aspose.Slides cannot save changed properties from that metadata-only object because the public properties must remain consistent with the corresponding data inside the encrypted presentation. Updating them therefore requires the correct opening password and a complete load.
The example requires an encrypted PPTX presentation with public document properties and a known opening password. It opens the complete presentation with LoadOptions::setPassword, updates public built-in properties, and saves the result. It then uses PresentationInfo::isEncrypted to verify that encryption is preserved and reopens the public metadata without a password to verify the new values:
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;
use aspose\slides\PresentationFactory;
use aspose\slides\SaveFormat;
$inputPath = "public-properties-encrypted.pptx";
$outputPath = "updated-public-properties-encrypted.pptx";
$loadOptions = new LoadOptions();
$loadOptions->setPassword("open_password");
$presentation = new Presentation($inputPath, $loadOptions);
try {
$documentProperties = $presentation->getDocumentProperties();
$documentProperties->setTitle("Updated Product Roadmap");
$documentProperties->setKeywords("roadmap, planning, indexed");
$presentation->save($outputPath, SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
$presentationInfo = PresentationFactory::getInstance()->getPresentationInfo($outputPath);
echo("The presentation is encrypted: " . (java_values($presentationInfo->isEncrypted()) ? "true" : "false") . "\n");
$metadataLoadOptions = new LoadOptions();
$metadataLoadOptions->setOnlyLoadDocumentProperties(true);
$metadataPresentation = new Presentation($outputPath, $metadataLoadOptions);
try {
if (java_values($metadataPresentation->getProtectionManager()->isOnlyDocumentPropertiesLoaded())) {
echo("Title: " . $metadataPresentation->getDocumentProperties()->getTitle() . "\n");
echo("Keywords: " . $metadataPresentation->getDocumentProperties()->getKeywords() . "\n");
} else {
echo("The presentation was not loaded in document-properties-only mode." . "\n");
}
} finally {
$metadataPresentation->dispose();
}
If an application is not allowed to decrypt or load the presentation content, it must treat public properties of an encrypted PPTX file as read-only.
Access Built-in Properties
The DocumentProperties class exposes built-in metadata through getter methods, including getAuthor, getTitle, and getCreatedTime. This example opens an existing presentation and prints its stored metadata to the console. Values depend on the input presentation; some fields may be empty.
use aspose\slides\Presentation;
$presentation = new Presentation("AccessBuiltInProperties.pptx");
try {
$documentProperties = $presentation->getDocumentProperties();
echo("Category: " . $documentProperties->getCategory() . "\n");
echo("Content status: " . $documentProperties->getContentStatus() . "\n");
echo("Creation date: " . $documentProperties->getCreatedTime() . "\n");
echo("Author: " . $documentProperties->getAuthor() . "\n");
echo("Comments: " . $documentProperties->getComments() . "\n");
echo("Keywords: " . $documentProperties->getKeywords() . "\n");
echo("Last modified by: " . $documentProperties->getLastSavedBy() . "\n");
echo("Manager: " . $documentProperties->getManager() . "\n");
echo("Modified date: " . $documentProperties->getLastSavedTime() . "\n");
echo("Presentation format: " . $documentProperties->getPresentationFormat() . "\n");
echo("Last print date: " . $documentProperties->getLastPrinted() . "\n");
echo("Is shared between producers: " . (java_values($documentProperties->getSharedDoc()) ? "true" : "false") . "\n");
echo("Subject: " . $documentProperties->getSubject() . "\n");
echo("Title: " . $documentProperties->getTitle() . "\n");
} finally {
$presentation->dispose();
}
Modify Built-in Properties
To update built-in metadata, use the setter methods on the object returned by Presentation::getDocumentProperties. This example opens an existing presentation, calls setAuthor, setTitle, setSubject, setComments, and setManager, then saves the updated presentation with Presentation::save. The saved PPTX contains the new metadata.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation("ModifyBuiltInProperties.pptx");
try {
$documentProperties = $presentation->getDocumentProperties();
$documentProperties->setAuthor("Aspose.Slides for PHP via Java");
$documentProperties->setTitle("Manage PowerPoint Presentation Properties");
$documentProperties->setSubject("Modify Built-in Properties");
$documentProperties->setComments("Aspose description");
$documentProperties->setManager("Aspose manager");
$presentation->save("DocumentProperties_output.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Manage the Hyperlink Base
DocumentProperties::getHyperlinkBase returns the document-level base for relative hyperlinks. Use DocumentProperties::setHyperlinkBase to change or clear it. This is useful when moving a presentation and its linked files to another location. It is separate from an individual hyperlink’s Hyperlink::getExternalUrl: changing the base does not rewrite the stored link addresses or change absolute destinations.
The example requires a presentation containing both a relative link, such as target.html, and an absolute link, such as https://example.org/absolute.html. It reads the existing base, assigns a new base address, and saves and reopens the presentation to check the value. It then clears the base with an empty string and verifies the empty value in a separate saved file. Replace the example base address with the location of your linked files.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation("hyperlinks.pptx");
try {
echo("Original base: " . $presentation->getDocumentProperties()->getHyperlinkBase() . "\n");
$newBase = "https://example.com/new/";
$presentation->getDocumentProperties()->setHyperlinkBase($newBase);
$presentation->save("hyperlinks-updated.pptx", SaveFormat::Pptx);
$updatedPresentation = new Presentation("hyperlinks-updated.pptx");
try {
echo("Base preserved: " . ((string) $updatedPresentation->getDocumentProperties()->getHyperlinkBase() === $newBase ? "true" : "false") . "\n");
$updatedPresentation->getDocumentProperties()->setHyperlinkBase("");
$updatedPresentation->save("hyperlinks-cleared.pptx", SaveFormat::Pptx);
$clearedPresentation = new Presentation("hyperlinks-cleared.pptx");
try {
echo("Base cleared: " . ((string) $clearedPresentation->getDocumentProperties()->getHyperlinkBase() === "" ? "true" : "false") . "\n");
} finally {
$clearedPresentation->dispose();
}
} finally {
$updatedPresentation->dispose();
}
} finally {
$presentation->dispose();
}
The two verification messages should print true. Clearing the base leaves the individual hyperlink addresses intact.
A relative link to target.pptx opened old/target.pptx when the base pointed to the old folder. After changing the base to the new folder, saving, and reopening the presentation, the same link opened new/target.pptx. An absolute link continued to open the same file. Test your relative links in PowerPoint before and after moving the presentation or changing its base.
Add Custom Presentation Properties
Custom properties store metadata that has no corresponding built-in field. The DocumentProperties::set_Item method lets you assign a value by property name. This example creates a presentation, adds two text values and an integer version value, and saves the presentation with Presentation::save. Assigning a value to an existing name replaces that property’s value.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$documentProperties = $presentation->getDocumentProperties();
$documentProperties->set_Item("Reviewed by", "John Smith");
$documentProperties->set_Item("Confidentiality level", "Internal");
$documentProperties->set_Item("Document version", 2);
$presentation->save("CustomDocumentProperties_output.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Access and Modify Custom Properties
This example opens a presentation containing custom properties and uses getCountOfCustomProperties to iterate over them. getCustomPropertyName accepts a zero-based index and returns the name used by DocumentProperties::set_Item. The example prints each original name and value, replaces every value with a numbered string regardless of its original type, and saves the changes. If there are no custom properties, the loop makes no changes.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation("AccessAndModifyProperties.pptx");
try {
$documentProperties = $presentation->getDocumentProperties();
for ($i = 0; $i < java_values($documentProperties->getCountOfCustomProperties()); $i++) {
$propertyName = $documentProperties->getCustomPropertyName($i);
$propertyValue = $documentProperties->get_Item($propertyName);
echo("Custom property name: " . $propertyName . "\n");
echo("Custom property value: " . $propertyValue . "\n");
$documentProperties->set_Item($propertyName, "New Value " . ($i + 1));
}
$presentation->save("CustomProperties_output.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Live Example
Try the View & Edit PowerPoint Metadata online app to see how to work with document properties using the Aspose.Slides API:
FAQ
How can I remove a built-in property from a presentation?
Built-in properties are an integral part of the presentation and cannot be removed entirely. However, you can either change their values or set them to empty if allowed by the specific property.
What happens if I add a custom property that already exists?
If you add a custom property that already exists, its existing value will be overwritten with the new one. You do not need to remove or check the property beforehand, as Aspose.Slides automatically updates the property’s value.
Can I access presentation properties without fully loading the presentation?
Yes. Use PresentationFactory::getPresentationInfo and then PresentationInfo::readDocumentProperties to read stored document metadata without creating a Presentation instance. See Build a Lightweight Presentation Inventory for a complete reporting example and format-specific limitations.
Can I read public properties of an encrypted presentation without its opening password?
Yes. The presentation must have been encrypted after calling ProtectionManager::setEncryptDocumentProperties with false, and it must be loaded after calling LoadOptions::setOnlyLoadDocumentProperties with true.
Can I update an encrypted PPTX file in document-properties-only mode?
No. Public and encrypted property data must remain consistent, so updating an encrypted PPTX file requires loading the complete presentation with the correct opening password.
