Files
docx-js/demo/54-custom-properties.ts

28 lines
914 B
TypeScript
Raw Normal View History

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 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
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);
});