Manage Presentation Properties in C++
Introduction
Aspose.Slides supports two types of document properties: Built-in and Custom. Both of these property types can easily be accessed and managed using the Aspose.Slides API.
Aspose.Slides allows you to work with presentation document properties through the IDocumentProperties interface. An instance of this interface is returned by IPresentation::get_DocumentProperties. The following examples show how to read, modify, and manage these properties.
Note
Please note that you cannot set values against the Application and Producer fields, because Aspose Ltd. and Aspose.Slides for C++ x.x.x will be displayed against these fields.Manage Presentation Properties
Microsoft PowerPoint provides a feature to add some properties to the presentation files. These document properties allow some useful information to be stored along with the documents (presentation files). There are two kinds of document properties as follows
- System Defined (Built-in) Properties
- User Defined (Custom) Properties
Built-in properties contain general information about the document like document title, author’s name, document statistics and so on. Custom properties are those ones, which are defined by the users as Name/Value pairs, where both name and value are defined by the user. Using Aspose.Slides for C++, developers can access and modify the values of built-in properties as well as custom properties. Microsoft PowerPoint 2007 allows managing the document properties of the presentation files. All you have to do is to click the Office icon and further Prepare | Properties | Advanced Properties menu item of the Microsoft PowerPoint 2007. After you select Advanced Properties menu item, a dialog would appear allowing you to manage the document properties of the PowerPoint file. In the Properties Dialog, you can see that there are many tab pages like General, Summary, Statistics, Contents and Custom. All these tab pages allow configuring different kinds of information related to the PowerPoint files. Custom tab is used to manage custom properties of the PowerPoint files.
Read Public Properties from an Encrypted Presentation
An opening password normally protects both presentation content and document properties. When a presentation is encrypted by passing false to IProtectionManager::set_EncryptDocumentProperties, its document properties remain public. An application can then pass true to LoadOptions::set_OnlyLoadDocumentProperties and read the public metadata without supplying the opening password.
set_OnlyLoadDocumentProperties 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 following example verifies the loading mode through IProtectionManager::get_IsOnlyDocumentPropertiesLoaded and then reads built-in properties through IPresentation::get_DocumentProperties:
#include <DOM/IDocumentProperties.h>
#include <DOM/IProtectionManager.h>
#include <DOM/LoadOptions.h>
#include <DOM/Presentation.h>
#include <system/console.h>
using namespace Aspose::Slides;
using namespace System;
auto loadOptions = MakeObject<LoadOptions>();
loadOptions->set_OnlyLoadDocumentProperties(true);
auto presentation = MakeObject<Presentation>(u"public-properties-encrypted.pptx", loadOptions);
if (presentation->get_ProtectionManager()->get_IsOnlyDocumentPropertiesLoaded())
{
auto properties = presentation->get_DocumentProperties();
Console::WriteLine(u"Author: " + properties->get_Author());
Console::WriteLine(u"Title: " + properties->get_Title());
Console::WriteLine(u"Keywords: " + properties->get_Keywords());
}
else
{
Console::WriteLine(u"The presentation was not loaded in document-properties-only mode.");
}
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 get_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 set_OnlyLoadDocumentProperties(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 following example opens the presentation with LoadOptions::set_Password, updates public built-in properties, and saves the result. It then uses IPresentationInfo::get_IsEncrypted to verify that encryption is preserved and reopens the public metadata without a password to verify the new values:
#include <DOM/IDocumentProperties.h>
#include <DOM/IPresentationInfo.h>
#include <DOM/IProtectionManager.h>
#include <DOM/LoadOptions.h>
#include <DOM/Presentation.h>
#include <DOM/PresentationFactory.h>
#include <Export/SaveFormat.h>
#include <system/console.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
const String inputPath = u"public-properties-encrypted.pptx";
const String outputPath = u"updated-public-properties-encrypted.pptx";
{
auto loadOptions = MakeObject<LoadOptions>();
loadOptions->set_Password(u"open_password");
auto presentation = MakeObject<Presentation>(inputPath, loadOptions);
presentation->get_DocumentProperties()->set_Title(u"Updated Product Roadmap");
presentation->get_DocumentProperties()->set_Keywords(u"roadmap, planning, indexed");
presentation->Save(outputPath, SaveFormat::Pptx);
presentation->Dispose();
}
auto presentationInfo = PresentationFactory::get_Instance()->GetPresentationInfo(outputPath);
Console::WriteLine(presentationInfo->get_IsEncrypted() ? u"The presentation is encrypted." : u"The presentation is not encrypted.");
auto metadataLoadOptions = MakeObject<LoadOptions>();
metadataLoadOptions->set_OnlyLoadDocumentProperties(true);
auto metadataPresentation = MakeObject<Presentation>(outputPath, metadataLoadOptions);
if (metadataPresentation->get_ProtectionManager()->get_IsOnlyDocumentPropertiesLoaded())
{
Console::WriteLine(u"Title: " + metadataPresentation->get_DocumentProperties()->get_Title());
Console::WriteLine(u"Keywords: " + metadataPresentation->get_DocumentProperties()->get_Keywords());
}
else
{
Console::WriteLine(u"The presentation was not loaded in document-properties-only mode.");
}
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
These properties as exposed by IDocumentProperties object include: Creator(Author), Description, KeyWords Created (Creation Date), Modified Modification Date, Printed Last Print Date, LastModifiedBy, Keywords, SharedDoc (Is shared between different producers?), PresentationFormat, Subject and Title
Modify Built-in Properties
Modifying the built-in properties of presentation files is as easy as that of accessing them. You can simply assign a string value to any desired property and the property value would be modified. In the example given below, we have demonstrated that how we can modify the built-in document properties of the presentation file.
Add Custom Presentation Properties
Aspose.Slides for C++ also allows developers to add the custom the values for presentation Document properties. An example is given below that shows how to set the custom properties for a presentation.
#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Instantiate the Presentation class
auto presentation = System::MakeObject<Presentation>();
// Getting Document Properties
auto documentProperties = presentation->get_DocumentProperties();
// Adding Custom properties
documentProperties->idx_set(u"New Custom", ObjectExt::Box<int32_t>(12));
documentProperties->idx_set(u"My Name", ObjectExt::Box<String>(u"Mudassir"));
documentProperties->idx_set(u"Custom", ObjectExt::Box<int32_t>(124));
// Getting property name at particular index
String getPropertyName = documentProperties->GetCustomPropertyName(2);
// Removing selected property
documentProperties->RemoveCustomProperty(getPropertyName);
// Saving presentation
presentation->Save(u"CustomDocumentProperties_out.pptx", SaveFormat::Pptx);
Access and Modify Custom Properties
Aspose.Slides for C++ also allows developers to access the values of custom properties. An example is given below that shows how can you access and modify all of these custom properties for a presentation.
Set Proofing Language
Aspose.Slides provides the LanguageId property (exposed by the PortionFormat class) to allow you to set the proofing language for a PowerPoint document. The proofing language is the language for which spellings and grammar in the PowerPoint are checked.
This C++ code shows you how to set the proofing language for a PowerPoint:
#include <DOM/AutoShape.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/IFontData.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortionCollection.h>
#include <DOM/IPortionFormat.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Portion.h>
#include <DOM/Presentation.h>
using namespace Aspose::Slides;
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"sample.pptx");
System::SharedPtr<AutoShape> autoShape = System::ExplicitCast<AutoShape>(pres->get_Slide(0)->get_Shape(0));
System::SharedPtr<IParagraph> paragraph = autoShape->get_TextFrame()->get_Paragraph(0);
System::SharedPtr<IPortionCollection> portions = paragraph->get_Portions();
portions->Clear();
System::SharedPtr<Portion> newPortion = System::MakeObject<Portion>();
System::SharedPtr<IFontData> font = System::MakeObject<FontData>(u"SimSun");
System::SharedPtr<IPortionFormat> portionFormat = newPortion->get_PortionFormat();
portionFormat->set_ComplexScriptFont(font);
portionFormat->set_EastAsianFont(font);
portionFormat->set_LatinFont(font);
portionFormat->set_LanguageId(u"zh-CN");
// set the Id of a proofing language
newPortion->set_Text(u"1。");
portions->Add(newPortion);
Set Default Language
This C++ code shows you how to set the default language for an entire PowerPoint presentation:
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/LoadOptions.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <system/console.h>
using namespace Aspose::Slides;
System::SharedPtr<LoadOptions> loadOptions = System::MakeObject<LoadOptions>();
loadOptions->set_DefaultTextLanguage(u"en-US");
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(loadOptions);
// Adds a new rectangle shape with text
System::SharedPtr<IAutoShape> shp = pres->get_Slide(0)->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50.0f, 50.0f, 150.0f, 50.0f);
System::SharedPtr<ITextFrame> textFrame = shp->get_TextFrame();
textFrame->set_Text(u"New Text");
// Checks the first portion language
System::Console::WriteLine(textFrame->get_Paragraph(0)->get_Portion(0)->get_PortionFormat()->get_LanguageId());
Live Example
Try Aspose.Slides Metadata online app to see how to work with document properties via 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 IPresentationFactory::GetPresentationInfo and then IPresentationInfo::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 by passing false to set_EncryptDocumentProperties, and it must be loaded by passing true to set_OnlyLoadDocumentProperties.
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.
