Mandatory Sections

This commit is contained in:
Dolan Miu
2019-07-31 08:48:02 +01:00
parent bf80311ef7
commit ac5b15d0e3
63 changed files with 1194 additions and 1588 deletions

View File

@ -1,27 +1,26 @@
// Multiple sections and headers
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
import { Document, Footer, Header, Packer, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
const doc = new Document();
const paragraph = new Paragraph("Hello World").pageBreak();
doc.add(paragraph);
const header = doc.createHeader();
header.add(new Paragraph("Header on another page"));
const footer = doc.createFooter();
footer.add(new Paragraph("Footer on another page"));
doc.addSection({
children: [new Paragraph("Hello World").pageBreak()],
});
doc.addSection({
headers: {
default: new Header({
children: [new Paragraph("First Default Header on another page")],
}),
},
footers: {
default: new Footer({
children: [new Paragraph("Footer on another page")],
}),
},
properties: {
headers: {
default: header,
},
footers: {
default: footer,
},
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
@ -29,39 +28,53 @@ doc.addSection({
});
doc.addSection({
headers: {
default: new Header({
children: [new Paragraph("Second Default Header on another page")],
}),
},
footers: {
default: new Footer({
children: [new Paragraph("Footer on another page")],
}),
},
size: {
orientation: PageOrientation.LANDSCAPE,
},
properties: {
headers: {
default: header,
},
footers: {
default: footer,
},
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
orientation: PageOrientation.LANDSCAPE,
},
children: [new Paragraph("hello in landscape")],
});
const header2 = doc.createHeader();
const pageNumber = new TextRun("Page number: ").pageNumber();
header2.add(new Paragraph({}).addRun(pageNumber));
doc.addSection({
properties: {
headers: {
default: header2,
},
headers: {
default: new Header({
children: [
new Paragraph({
children: [new TextRun("Page number: ").pageNumber()],
}),
],
}),
},
size: {
orientation: PageOrientation.PORTRAIT,
},
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")],
});
doc.addSection({
headers: {
default: new Header({
children: [
new Paragraph({
children: [new TextRun("Page number: ").pageNumber()],
}),
],
}),
},
properties: {
headers: {
default: header2,
},
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN,
orientation: PageOrientation.PORTRAIT,
},
@ -73,13 +86,21 @@ doc.addSection({
});
doc.addSection({
headers: {
default: new Header({
children: [
new Paragraph({
children: [new TextRun("Page number: ").pageNumber()],
}),
],
}),
},
size: {
orientation: PageOrientation.PORTRAIT,
},
properties: {
headers: {
default: header2,
},
pageNumberFormatType: PageNumberFormat.DECIMAL,
pageNumberStart: 25,
orientation: PageOrientation.PORTRAIT,
},
children: [
new Paragraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section."),