2019-10-29 12:55:15 +02:00
|
|
|
// Example of making content of section vertically aligned
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build";
|
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
|
|
|
doc.addSection({
|
|
|
|
properties: {
|
2019-10-31 13:54:53 +02:00
|
|
|
verticalAlign: SectionVerticalAlignValue.CENTER,
|
2019-10-29 12:55:15 +02:00
|
|
|
},
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun("Hello World"),
|
|
|
|
new TextRun({
|
|
|
|
text: "Foo Bar",
|
|
|
|
bold: true,
|
|
|
|
}),
|
|
|
|
new TextRun({
|
2019-11-21 01:02:46 +00:00
|
|
|
text: "\tGithub is the best",
|
2019-10-29 12:55:15 +02:00
|
|
|
bold: true,
|
2019-11-21 01:02:46 +00:00
|
|
|
}),
|
2019-10-29 12:55:15 +02:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|