Files
docx-js/demo/58-section-types.ts
2023-06-05 00:33:43 +01:00

92 lines
2.5 KiB
TypeScript

// Usage of different Section Types
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun, SectionType } from "docx";
const doc = new Document({
sections: [
{
properties: {},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
},
{
properties: {
type: SectionType.CONTINUOUS,
},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
},
{
properties: {
type: SectionType.ODD_PAGE,
},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
},
{
properties: {
type: SectionType.EVEN_PAGE,
},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
},
{
properties: {
type: SectionType.NEXT_PAGE,
},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});