Add custom properties demo

This commit is contained in:
Max Lay
2020-08-08 11:01:21 +12:00
parent fc87a73259
commit e65e7d6a32

View File

@ -0,0 +1,25 @@
// 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 from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
const doc = new Document(
// Standard properties
{ creator: "Creator", title: "Title", subject: "Subject", description: "Description" },
// No file properties
{},
// No sections
[],
[
{ name: "Subtitle", value: "Subtitle" },
{ name: "Address", value: "Address" },
]
);
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});