2021-03-16 00:57:27 +00:00
|
|
|
// 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, PageBreak, Paragraph, TextRun } from "../build";
|
|
|
|
|
|
|
|
const doc = new Document({
|
|
|
|
evenAndOddHeaderAndFooters: true,
|
2021-03-19 20:53:56 +00:00
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
default: new Header({
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
text: "Odd Header text",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Odd - Some more header text",
|
|
|
|
}),
|
|
|
|
],
|
2021-03-16 00:57:27 +00:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
even: new Header({
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
text: "Even header text",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Even - Some more header text",
|
|
|
|
}),
|
|
|
|
],
|
2021-03-16 00:57:27 +00:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
footers: {
|
|
|
|
default: new Footer({
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
text: "Odd Footer text",
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
even: new Footer({
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
text: "Even Cool Footer text",
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
},
|
2021-03-16 00:57:27 +00:00
|
|
|
children: [
|
|
|
|
new Paragraph({
|
2021-03-19 20:53:56 +00:00
|
|
|
children: [new TextRun("Hello World 1"), new PageBreak()],
|
2021-03-16 00:57:27 +00:00
|
|
|
}),
|
|
|
|
new Paragraph({
|
2021-03-19 20:53:56 +00:00
|
|
|
children: [new TextRun("Hello World 2"), new PageBreak()],
|
2021-03-16 00:57:27 +00:00
|
|
|
}),
|
|
|
|
new Paragraph({
|
2021-03-19 20:53:56 +00:00
|
|
|
children: [new TextRun("Hello World 3"), new PageBreak()],
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
children: [new TextRun("Hello World 4"), new PageBreak()],
|
2021-03-16 01:02:33 +00:00
|
|
|
}),
|
|
|
|
new Paragraph({
|
2021-03-19 20:53:56 +00:00
|
|
|
children: [new TextRun("Hello World 5"), new PageBreak()],
|
2021-03-16 00:57:27 +00:00
|
|
|
}),
|
|
|
|
],
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2021-03-16 00:57:27 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|