From 9bda9e8375803221d5a026396188b45dd430fa0b Mon Sep 17 00:00:00 2001 From: Dolan Date: Mon, 8 Mar 2021 22:51:46 +0000 Subject: [PATCH] #801 Add example to offset header and footer --- demo/59-header-footer-margins.ts | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 demo/59-header-footer-margins.ts diff --git a/demo/59-header-footer-margins.ts b/demo/59-header-footer-margins.ts new file mode 100644 index 0000000000..35b1992fc5 --- /dev/null +++ b/demo/59-header-footer-margins.ts @@ -0,0 +1,48 @@ +// Move + offset header and footer +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Footer, Header, Packer, Paragraph } from "../build"; + +const doc = new Document(); + +doc.addSection({ + properties: { + header: 100, + footer: 50, + }, + headers: { + default: new Header({ + children: [ + new Paragraph({ + text: "Header text", + indent: { + left: -400, + }, + }), + new Paragraph({ + text: "Some more header text", + indent: { + left: -600, + }, + }), + ], + }), + }, + footers: { + default: new Footer({ + children: [ + new Paragraph({ + text: "Footer text", + indent: { + left: -400, + }, + }), + ], + }), + }, + children: [new Paragraph("Hello World")], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +});