2018-08-21 02:46:21 +01:00
|
|
|
// Multiple sections and headers
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2018-09-18 00:51:35 +01:00
|
|
|
import { Document, FooterReferenceType, HeaderReferenceType, Packer, PageNumberFormat, PageOrientation, Paragraph } from "../build";
|
2018-08-21 02:46:21 +01:00
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
|
|
|
const paragraph = new Paragraph("Hello World").pageBreak();
|
|
|
|
|
|
|
|
doc.addParagraph(paragraph);
|
|
|
|
|
|
|
|
const header = doc.createHeader();
|
|
|
|
header.createParagraph("Header on another page");
|
|
|
|
const footer = doc.createFooter();
|
|
|
|
footer.createParagraph("Footer on another page");
|
|
|
|
|
|
|
|
doc.addSection({
|
2018-09-05 10:02:42 +03:00
|
|
|
headers: [{headerId: header.Header.ReferenceId, headerType: HeaderReferenceType.FIRST}],
|
|
|
|
footers: [{footerId: footer.Footer.ReferenceId, footerType: FooterReferenceType.FIRST}],
|
2018-08-21 02:46:21 +01:00
|
|
|
pageNumberStart: 1,
|
|
|
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
|
|
});
|
|
|
|
|
|
|
|
doc.createParagraph("hello");
|
|
|
|
|
|
|
|
doc.addSection({
|
2018-09-05 10:02:42 +03:00
|
|
|
headers: [{headerId: header.Header.ReferenceId, headerType: HeaderReferenceType.FIRST}],
|
|
|
|
footers: [{footerId: footer.Footer.ReferenceId, footerType: FooterReferenceType.FIRST}],
|
2018-08-21 02:46:21 +01:00
|
|
|
pageNumberStart: 1,
|
|
|
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
|
|
orientation: PageOrientation.LANDSCAPE,
|
|
|
|
});
|
|
|
|
|
|
|
|
doc.createParagraph("hello in landscape");
|
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|