Document properties record information that lies outside the content. Built-in properties have names and meanings defined by Word and cover the title, subject, author, company, category, keywords, and comments; custom properties have names and values defined by the business and are often used for fields such as contract numbers, review status, and project numbers. Properties do not take part in body layout, yet they provide the basis for archiving, retrieval, and workflow decisions.
Spire.Doc for C++ reads and writes built-in properties through Document->GetBuiltinDocumentProperties() and manages custom properties through Document->GetCustomDocumentProperties(). A custom value is passed as an Object, and a string is wrapped in a String object; when reading, DocumentProperty->ToString(), GetName(), and GetValueType() return the value, the name, and the type.
This article covers three features:
- Set built-in document properties
- Add custom document properties
- Read and remove custom document properties
The entry points and uses of the two kinds of properties are as follows:
| Category | Entry point | Typical fields |
|---|---|---|
| Built-in properties | GetBuiltinDocumentProperties() |
Title, subject, author, company, category, keywords, comments |
| Custom properties | GetCustomDocumentProperties() |
Business fields such as contract number, review status, and archive date |
Built-in properties are visible on the Info page and on the Details tab of the file properties; custom properties are stored in docProps/custom.xml in the document package and are parsed by the program that reads them.
Install Spire.Doc for C++
There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet; the other is to download the package from our website and copy the libraries into your program. Installing through NuGet is simpler and is the recommended approach.
- In Visual Studio, open the NuGet Package Manager, search for
Spire.Doc.Cpp, and install it. - Alternatively, run
nuget install Spire.Doc.Cppin the project directory, and then add the package'sincludeandlibfolders to the project.
An integrated project needs to reference the corresponding import library and to ensure that dependency files such as SpireDocCpp.dll and Spire.Doc.Base.dll are present in the run directory. For detailed configuration instructions, refer to How to Integrate Spire.Doc for C++ in a C++ Application.
Set Built-in Document Properties
Built-in properties are provided by BuiltinDocumentProperties, and the common fields each have a corresponding Set* and Get* method. The example loads a project progress report, writes the title, subject, author, manager, company, category, keywords, and comments, and then reads three of them back to confirm the result.
| Operation | Method | Description |
|---|---|---|
| Title | SetTitle(string) / GetTitle() |
Document title |
| Subject | SetSubject(string) |
Document subject |
| Author | SetAuthor(string) |
Creator |
| Manager | SetManager(string) |
Responsible person or department |
| Company | SetCompany(string) |
Owning company |
| Category | SetCategory(string) |
Document category |
| Keywords | SetKeywords(string) |
Multiple keywords separated by commas |
| Comments | SetComments(string) |
Supplementary notes |
The detailed steps are as follows.
- Create a Document object and call LoadFromFile() to load the sample document.
- Call GetBuiltinDocumentProperties() to obtain the built-in property object.
- Call SetTitle(), SetSubject(), SetAuthor(), SetManager(), SetCompany(), SetCategory(), SetKeywords(), and SetComments() in turn to write the fields.
- Call GetTitle(), GetAuthor(), and GetCompany() to read and output the result.
- Call SaveToFile() to save the document.
The code for setting the built-in document properties is shown below.
#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/BuiltinDocumentProperties.h"
#include "Spire/Doc/Document.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/common/h/Stream.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;
int main()
{
SetConsoleOutputCP(CP_UTF8);
//Load the project progress report
intrusive_ptr<Document> document = new Document();
document->LoadFromFile("Template.docx");
//Write the built-in summary properties
intrusive_ptr<BuiltinDocumentProperties> properties =
document->GetBuiltinDocumentProperties();
properties->SetTitle("Smart Warehouse Management Platform Project Progress Report");
properties->SetSubject("Q4 2026 Project Progress");
properties->SetAuthor("Chen Li");
properties->SetManager("Project Management Department");
properties->SetCompany("Beichen Supply Chain Co., Ltd.");
properties->SetCategory("Internal Report");
properties->SetKeywords("warehousing, project progress, 2026Q4, internal");
properties->SetComments("Reviewed by the project management committee and archived as quarterly material.");
cout << "Title: " << properties->GetTitle() << endl;
cout << "Author: " << properties->GetAuthor() << endl;
cout << "Company: " << properties->GetCompany() << endl;
//Save and close the document
document->SaveToFile("Output/BuiltinProperties.docx", FileFormat::Docx);
document->Close();
return 0;
}
The console output shows that the three fields have been written and can be read back:
Title: Smart Warehouse Management Platform Project Progress Report
Author: Chen Li
Company: Beichen Supply Chain Co., Ltd.
After saving, open the Details tab of the file properties; the title, subject, author, category, comments, company, and manager all appear in the property list:

Built-in Properties Are Written to the File When the Document Is Saved
Methods such as SetTitle() modify the property object in memory, and the values are written into the document package only when SaveToFile() is called. When a document is generated from a template, the property values already present in the template are retained until the moment of saving and are then replaced by the values that are explicitly set. The example assigns all eight fields one by one, and fields without an assignment keep the value from the template.
Property Values Do Not Take Part in Body Layout
Built-in properties are metadata. They do not appear on the page, and they do not affect pagination or printing. The page saved by the example is identical to the page before loading, and the change is visible only in the file properties panel. When a title or an author needs to be displayed on the page, insert the corresponding content into the body, a header, or a footer; the properties themselves provide no layout output.
Statistical Fields Are Read-Only
Statistical fields such as WordCount, CharCount, PageCount, and ParagraphCount are calculated when the document is saved and offer only Get* methods, with no corresponding Set*. The example sets only the summary fields. When a page count or a word count is needed, read these fields rather than attempting to write them.
Add Custom Document Properties
The names and values of custom properties are determined by the business. The second parameter of CustomDocumentProperties->Add(name, value) is an intrusive_ptr<Object>, so a string is first wrapped in a String object. The example adds three properties, namely the contract number, the review status, and the archive date, and then iterates over the collection to output the name, the value, and the value type of each property.
| Operation | Method | Description |
|---|---|---|
| Add a property | Add(name, Object) |
The value is an object derived from Object |
| Add a string | Add(name, new String(value)) |
Uses Spire::Doc::Common::String |
| Count the properties | GetCount() |
Returns the number of properties |
| Get a property by index | GetItem(index) |
Returns a DocumentProperty |
| Read the name | DocumentProperty->GetName() |
Property key |
| Read the value | DocumentProperty->ToString() |
Converts to a string |
| Read the type | GetValueType() |
Returns a PropertyValueType |
The detailed steps are as follows.
- Create a Document object and call LoadFromFile() to load the sample document.
- Call GetCustomDocumentProperties() to obtain the custom property collection.
- Call Add() three times to add string properties, each value wrapped in a String object.
- Call GetCount() to output the count, and call GetItem(index) in a loop to obtain each property.
- Call GetName(), ToString(), and GetValueType() to output the name, the value, and the type.
- Call SaveToFile() to save the document.
The code for adding custom document properties is shown below.
#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/CustomDocumentProperties.h"
#include "Spire/Doc/Document.h"
#include "Spire/Doc/DocumentProperty.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/common/h/Stream.h"
#include "Spire/Doc/common/h/System_String.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;
//Convert a property value type to a readable name
string GetTypeName(PropertyValueType type)
{
switch (type)
{
case PropertyValueType::String: return "String";
case PropertyValueType::Int:
case PropertyValueType::Int32: return "Integer";
case PropertyValueType::Date: return "Date";
case PropertyValueType::Boolean: return "Boolean";
case PropertyValueType::Double:
case PropertyValueType::Float: return "Number";
default: return "Other";
}
}
int main()
{
SetConsoleOutputCP(CP_UTF8);
//Load the project progress report
intrusive_ptr<Document> document = new Document();
document->LoadFromFile("Template.docx");
//Add three custom properties; the values are passed as String objects
intrusive_ptr<CustomDocumentProperties> properties =
document->GetCustomDocumentProperties();
properties->Add("Contract Number", new String("HT-2026-018"));
properties->Add("Review Status", new String("Approved"));
properties->Add("Archive Date", new String("2026-12-31"));
//Iterate over the custom properties
cout << "Custom property count: " << properties->GetCount() << endl;
for (int i = 0; i < properties->GetCount(); i++)
{
intrusive_ptr<DocumentProperty> property = properties->GetItem(i);
cout << property->GetName() << " = " << property->ToString()
<< " (" << GetTypeName(property->GetValueType()) << ")" << endl;
}
//Save and close the document
document->SaveToFile("Output/CustomProperties.docx", FileFormat::Docx);
document->Close();
return 0;
}
The console output lists the name, the value, and the type of the three properties, all of which are of type String:
Custom property count: 3
Contract Number = HT-2026-018 (String)
Review Status = Approved (String)
Archive Date = 2026-12-31 (String)
The body of the saved document is unchanged, and the custom properties are written into the document package. In the figure below, the right side shows the property list printed by the program:

Values Must Be Wrapped as Object
The second parameter of Add() is an intrusive_ptr<Object>, so a std::string cannot be passed directly. The example creates a Spire::Doc::Common::String with new String("HT-2026-018"); this type derives from Object and can be passed as the parameter. Property values are always passed as Object, and when reading, the value can be converted to a target type through ToInt(), ToDateTime(), or ToBool() on DocumentProperty.
Custom Properties Are Stored in custom.xml
After saving, the document package contains a new docProps/custom.xml, in which each property corresponds to one <property> element. The content generated by the example is shown below (excerpt):
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="Contract Number">
<vt:lpwstr>HT-2026-018</vt:lpwstr>
</property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="3" name="Review Status">
<vt:lpwstr>Approved</vt:lpwstr>
</property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="4" name="Archive Date">
<vt:lpwstr>2026-12-31</vt:lpwstr>
</property>
</Properties>
pid starts at 2 and increases, name holds the property key, and vt:lpwstr denotes a Unicode string.
Custom Properties Do Not Appear in the Details Tab
The Details tab of the Windows file properties lists only the standard fields recognized by the system, and the custom properties of a docx are not shown there. To check custom properties, read CustomDocumentProperties from a program or inspect docProps/custom.xml directly. The example therefore places the property list printed by the program next to the page.
Read and Remove Custom Document Properties
A single property is read with GetItem(name) or GetItem(index), which return a DocumentProperty, and removed with Remove(name). The example loads a document that contains three custom properties, outputs the count and the contract number, removes "Review Status", and then outputs the names of the remaining properties.
| Operation | Method | Description |
|---|---|---|
| Read by name | GetItem(name) |
Returns a DocumentProperty |
| Read by index | GetItem(index) |
Returns a DocumentProperty |
| Read the value | DocumentProperty->ToString() |
String form |
| Remove a property | Remove(name) |
Removes by name |
| Count after removal | GetCount() |
The count decreases by one |
The detailed steps are as follows.
- Create a Document object and call LoadFromFile() to load the document that contains the custom properties.
- Call GetCustomDocumentProperties() to obtain the property collection.
- Call GetCount() to output the count before removal.
- Call GetItem("Contract Number")->ToString() to read the value by name.
- Call Remove("Review Status") to remove the property, output the count again, and list the remaining names.
- Call SaveToFile() to save the result document.
The code for reading and removing custom document properties is shown below.
#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/CustomDocumentProperties.h"
#include "Spire/Doc/Document.h"
#include "Spire/Doc/DocumentProperty.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/common/h/Stream.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;
int main()
{
SetConsoleOutputCP(CP_UTF8);
//Load the document that contains three custom properties
intrusive_ptr<Document> document = new Document();
document->LoadFromFile("CustomProperties.docx");
intrusive_ptr<CustomDocumentProperties> properties =
document->GetCustomDocumentProperties();
cout << "Property count before removal: " << properties->GetCount() << endl;
//Read a single property by name
cout << "Contract Number: " << properties->GetItem("Contract Number")->ToString() << endl;
//Remove the Review Status property, then list the remaining names
properties->Remove("Review Status");
cout << "Property count after removal: " << properties->GetCount() << endl;
for (int i = 0; i < properties->GetCount(); i++)
{
cout << properties->GetItem(i)->GetName() << endl;
}
//Save and close the document
document->SaveToFile("Output/CustomPropertiesCleaned.docx", FileFormat::Docx);
document->Close();
return 0;
}
The console output shows that the property count falls from 3 to 2, and that the two remaining properties are the contract number and the archive date:
Property count before removal: 3
Contract Number: HT-2026-018
Property count after removal: 2
Contract Number
Archive Date
The saved document no longer contains "Review Status", and docProps/custom.xml keeps only two properties:

Removing a Property Does Not Affect the Body
Custom properties are document metadata, and removing one leaves both the body content and the layout unchanged. After the example removes "Review Status", the page and the paragraphs stay as they were, and the change is visible only in the property collection and in custom.xml. When a review status needs to be displayed on the page, reference the property value through a field or through text, and handle the related content when the property is removed.
Reading by Name Is Case-Sensitive
The name passed to GetItem("Contract Number") must match the key written by Add() exactly. When the names differ, the call does not return the intended property. When iterating, obtain the actual key with GetItem(index)->GetName() and compare it with the business field, which avoids a failed read caused by a difference in the name.
Changes Are Written to the File Only on Save
Remove() modifies the property collection in memory, and the result is written into custom.xml only when SaveToFile() is called. The example saves immediately after the removal, and the result document contains two properties. When the original file needs to be kept, copy the document before the removal or save the result under a new file name.
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
