Demo 16 was updated to show how page number types format and start work.

This commit is contained in:
Sergio Mendonça
2018-11-09 09:14:38 -02:00
parent 5552f9d834
commit 39cef5e61d

View File

@ -1,7 +1,7 @@
// Multiple sections and headers // Multiple sections and headers
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph } from "../build"; import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document();
@ -41,6 +41,40 @@ doc.addSection({
doc.createParagraph("hello in landscape"); doc.createParagraph("hello in landscape");
const header2 = doc.createHeader();
const pageNumber = new TextRun("Page number: ").pageNumber();
header2.createParagraph().addRun(pageNumber);
doc.addSection({
headers: {
default: header2,
},
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph("Page number in the header must be 2, because it continues from the previous section.");
doc.addSection({
headers: {
default: header2,
},
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN,
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph("Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.");
doc.addSection({
headers: {
default: header2,
},
pageNumberFormatType: PageNumberFormat.DECIMAL,
pageNumberStart: 25,
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section.");
const packer = new Packer(); const packer = new Packer();
packer.toBuffer(doc).then((buffer) => { packer.toBuffer(doc).then((buffer) => {