2018-08-21 02:46:21 +01:00
|
|
|
// Add text to header and footer
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2019-06-13 01:07:00 +01:00
|
|
|
import { Document, Packer, Paragraph } from "../build";
|
2018-08-21 02:46:21 +01:00
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.add(new Paragraph("Hello World"));
|
2018-08-21 02:46:21 +01:00
|
|
|
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.Header.add(new Paragraph("Header text"));
|
|
|
|
doc.Footer.add(new Paragraph("Footer text"));
|
2018-08-21 02:46:21 +01:00
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|