Note
This article describes how to dynamically update document metadata in the Classic DOCX templating engine, which is obsolete and lacks modern features. We suggest using the Modern templating engine instead. Click here for updated instructions.
There are 2 ways of updating a document metadata:
Change a document metadata just using JSON tokens.
Check out this JSON:
{
"title": "Invoice",
"subject": "Water pumps",
"creator": "David Navarro"
}
I added the tags {{title}}
, {{subject}}
and {{creator}}
in the document metadata and after applying the JSON,
it will be replaced with “Invoice”, “Water pumps” and “David Navarro” accordingly.
You can also define a document metadata values using @metadata
object at the root of the JSON.
For this you need to pass @metadata
JSON object along with other data.
Documents will automatically detect this @metadata
object and apply corresponding values to the document metadata.
There is no need to put tokens inside the document “Properties” dialog.
{
"@metadata": {
"title": "Some title",
"description": "Some description",
"subject": "",
"creator": "David Navarro",
"keywords": "",
"lastModifiedBy": "Plumsail Inc"
},
"prop1": "val1",
"prop2": "val2",
"propN": "valN"
}
I define all fields in the JSON. If lastModifiedBy
and creator
fields are not defined
then the engine inserts default values Plumsail Inc
и Plumsail
accordingly.
There is also one rule I need to mention: if the same token is used with the @metadata
object and with other tokens in the JSON:
{
"@metadata": {
"creator": "admin"
},
"creator": "David Navarro"
}
The token has a higher priority than the @metadata
object and the creator
tag will be replaced with the “David Navarro” value.