2018-08-21 02:46:21 +01:00
|
|
|
// Page numbers
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2021-03-15 19:02:04 +00:00
|
|
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
|
2018-08-21 02:46:21 +01:00
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
titlePage: true,
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
default: new Header({
|
2019-11-21 01:12:32 +00:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
children: [
|
|
|
|
new TextRun("My Title "),
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page ", PageNumber.CURRENT],
|
|
|
|
}),
|
|
|
|
],
|
2019-11-21 01:12:32 +00:00
|
|
|
}),
|
|
|
|
],
|
2019-07-31 08:48:02 +01:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
first: new Header({
|
2019-11-21 01:12:32 +00:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
children: [
|
|
|
|
new TextRun("First Page Header "),
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page ", PageNumber.CURRENT],
|
|
|
|
}),
|
|
|
|
],
|
2019-11-21 01:12:32 +00:00
|
|
|
}),
|
|
|
|
],
|
2019-07-31 08:48:02 +01:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
footers: {
|
|
|
|
default: new Footer({
|
2021-03-15 19:02:04 +00:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
children: [
|
|
|
|
new TextRun("My Title "),
|
|
|
|
new TextRun({
|
|
|
|
children: ["Footer - Page ", PageNumber.CURRENT],
|
|
|
|
}),
|
|
|
|
],
|
2021-03-15 19:02:04 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
first: new Footer({
|
2021-03-15 19:02:04 +00:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
children: [
|
|
|
|
new TextRun("First Page Footer "),
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page ", PageNumber.CURRENT],
|
|
|
|
}),
|
|
|
|
],
|
2021-03-15 19:02:04 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
children: [new TextRun("First Page"), new PageBreak()],
|
|
|
|
}),
|
|
|
|
new Paragraph("Second Page"),
|
2021-03-15 19:02:04 +00:00
|
|
|
],
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-07-31 08:48:02 +01:00
|
|
|
],
|
2019-06-13 01:07:00 +01:00
|
|
|
});
|
2018-08-21 02:46:21 +01:00
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2018-08-21 02:46:21 +01:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|