2020-08-08 11:01:21 +12:00
|
|
|
// Custom Properties
|
|
|
|
// Custom properties are incredibly useful if you want to be able to apply quick parts or custom cover pages
|
|
|
|
// to the document in Word after the document has been generated. Standard properties (such as creator, title
|
|
|
|
// and subject) cover typical use cases, but sometimes custom properties are required.
|
|
|
|
|
|
|
|
import * as fs from "fs";
|
2023-06-05 00:33:43 +01:00
|
|
|
import { Document, Packer } from "docx";
|
2020-08-08 11:01:21 +12:00
|
|
|
|
|
|
|
const doc = new Document(
|
|
|
|
// Standard properties
|
2021-03-07 21:27:38 +00:00
|
|
|
{
|
|
|
|
creator: "Creator",
|
|
|
|
title: "Title",
|
|
|
|
subject: "Subject",
|
|
|
|
description: "Description",
|
|
|
|
customProperties: [
|
|
|
|
{ name: "Subtitle", value: "Subtitle" },
|
|
|
|
{ name: "Address", value: "Address" },
|
|
|
|
],
|
2021-03-20 01:20:14 +00:00
|
|
|
sections: [],
|
2021-03-07 21:27:38 +00:00
|
|
|
},
|
2020-08-08 11:01:21 +12:00
|
|
|
);
|
|
|
|
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|