Skip to main content

DocumentProperties

Struct DocumentProperties 

Source
pub struct DocumentProperties {
    pub title: Option<String>,
    pub subject: Option<String>,
    pub creator: Option<String>,
    pub keywords: Option<String>,
    pub description: Option<String>,
    pub last_modified_by: Option<String>,
    pub revision: Option<String>,
    pub created: Option<String>,
    pub modified: Option<String>,
    pub category: Option<String>,
    pub content_status: Option<String>,
}
Expand description

This document’s core properties (docProps/core.xml, CT_CoreProperties). Every field mirrors a Dublin Core / Dublin Core Terms element Word’s own File > Info panel shows and lets a user edit — None leaves the corresponding XML element out entirely (mirrors Word’s own behavior: an absent element is treated as an empty property, not a validation error). Dates (created/modified) are plain ISO-8601/W3CDTF strings (e.g. "2026-07-17T10:00:00Z"), not a dedicated date/time type — this crate has no date/time dependency, and two optional metadata fields don’t justify adding one; the caller is responsible for supplying a valid W3CDTF string, not validated when writing (same best-effort posture as Paragraph.numbering_id referencing a declaration that may not exist). A handful of CT_CoreProperties’ children are not modeled here (dc:identifier, dc:language, cp:lastPrinted, cp:version) — niche fields with no real demand seen yet, same scope-reduction posture as elsewhere in this crate.

Fields§

§title: Option<String>

The document’s title (dc:title), shown in Word’s title bar and File > Info panel.

§subject: Option<String>

The document’s subject (dc:subject).

§creator: Option<String>

The document’s author (dc:creator).

§keywords: Option<String>

Search keywords/tags (cp:keywords).

§description: Option<String>

A longer description of the document (dc:description) — shown as “Comments” in Word’s own File > Info panel despite the underlying element being dc:description.

§last_modified_by: Option<String>

The user who last modified the document (cp:lastModifiedBy).

§revision: Option<String>

The document’s revision number, as a plain string (cp:revision, schema-typed as xsd:string, even though Word itself always populates it with a decimal integer in practice).

§created: Option<String>

When the document was created (dcterms:created), a W3CDTF string. See this struct’s own doc comment for the string-not-a-type choice.

§modified: Option<String>

When the document was last modified (dcterms:modified), mirroring created.

§category: Option<String>

The document’s category (cp:category), a free-form classification string distinct from subject.

§content_status: Option<String>

The document’s content status (cp:contentStatus, e.g. “Draft”, “Final” — a free-form string, not a fixed enumeration).

Implementations§

Source§

impl DocumentProperties

Source

pub fn new() -> DocumentProperties

Creates an empty set of document properties (every field None).

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 17)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_title(self, title: impl Into<String>) -> DocumentProperties

Sets the document’s title and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 18)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_subject(self, subject: impl Into<String>) -> DocumentProperties

Sets the document’s subject and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 19)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_creator(self, creator: impl Into<String>) -> DocumentProperties

Sets the document’s author and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 20)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_keywords(self, keywords: impl Into<String>) -> DocumentProperties

Sets the document’s search keywords and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 21)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_description( self, description: impl Into<String>, ) -> DocumentProperties

Sets the document’s description and returns it for chaining. Shown as “Comments” in Word’s own File > Info panel — see this field’s doc comment.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 22)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_last_modified_by( self, last_modified_by: impl Into<String>, ) -> DocumentProperties

Sets who last modified the document and returns it for chaining.

Source

pub fn with_revision(self, revision: impl Into<String>) -> DocumentProperties

Sets the document’s revision number (as a string) and returns it for chaining.

Source

pub fn with_created(self, created: impl Into<String>) -> DocumentProperties

Sets when the document was created (a W3CDTF string, e.g. "2026-07-17T10:00:00Z") and returns it for chaining. Not validated — see this struct’s doc comment.

Source

pub fn with_modified(self, modified: impl Into<String>) -> DocumentProperties

Sets when the document was last modified (a W3CDTF string), mirroring with_created, and returns it for chaining.

Source

pub fn with_category(self, category: impl Into<String>) -> DocumentProperties

Sets the document’s category and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 23)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}
Source

pub fn with_content_status( self, content_status: impl Into<String>, ) -> DocumentProperties

Sets the document’s content status (e.g. "Draft", "Final") and returns it for chaining.

Examples found in repository?
examples/docx_metadata_and_protection.rs (line 24)
16fn main() -> office_toolkit::Result<()> {
17    let properties = DocumentProperties::new()
18        .with_title("Quarterly Report")
19        .with_subject("Q3 results")
20        .with_creator("Jane Doe")
21        .with_keywords("finance, quarterly, report")
22        .with_description("An example document showing document properties.")
23        .with_category("Finance")
24        .with_content_status("Draft");
25    let extended_properties = ExtendedProperties::new()
26        .with_company("Acme Corp.")
27        .with_manager("Jane Manager");
28
29    let metadata_document = Document::new()
30        .with_properties(properties)
31        .with_extended_properties(extended_properties)
32        .with_custom_property("ProjectCode", CustomPropertyValue::Text("Q3-2026".to_string()))
33        .with_custom_property("Budget", CustomPropertyValue::Number(125_000.0))
34        .with_custom_property("Approved", CustomPropertyValue::Bool(false))
35        .with_custom_property("RevisionCount", CustomPropertyValue::Int(3))
36        .with_track_changes(true)
37        .with_paragraph(Paragraph::with_text(
38            "This document carries standard properties (title/author/subject/...), four custom properties, \
39             and has track changes turned on — check File > Info in Word to see them.",
40        ));
41    let metadata_path = output_path("docx_metadata.docx");
42    metadata_document.save_to_file(&metadata_path)?;
43    println!("Wrote {}", metadata_path.display());
44
45    let protected_document = Document::new()
46        .with_protection(ProtectionKind::ReadOnly)
47        .with_paragraph(Paragraph::with_text(
48            "This document is protected as read-only — Word will ask for a password before allowing edits.",
49        ));
50    let protected_path = output_path("docx_protected.docx");
51    protected_document.save_to_file(&protected_path)?;
52    println!("Wrote {}", protected_path.display());
53
54    Ok(())
55}

Trait Implementations§

Source§

impl Clone for DocumentProperties

Source§

fn clone(&self) -> DocumentProperties

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DocumentProperties

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for DocumentProperties

Source§

fn default() -> DocumentProperties

Returns the “default value” for a type. Read more
Source§

impl Eq for DocumentProperties

Source§

impl PartialEq for DocumentProperties

Source§

fn eq(&self, other: &DocumentProperties) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DocumentProperties

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.