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";
|
2021-05-26 10:53:27 +03:00
|
|
|
import { Document, Packer, Paragraph, VerticalAlign, TextRun } from "../build";
|
2019-10-29 12:55:15 +02:00
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
properties: {
|
2021-05-26 10:53:27 +03:00
|
|
|
verticalAlign: VerticalAlign.CENTER,
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-10-29 12:55:15 +02:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun("Hello World"),
|
|
|
|
new TextRun({
|
|
|
|
text: "Foo Bar",
|
|
|
|
bold: true,
|
|
|
|
}),
|
|
|
|
new TextRun({
|
|
|
|
text: "\tGithub is the best",
|
|
|
|
bold: true,
|
|
|
|
}),
|
|
|
|
],
|
2019-11-21 01:02:46 +00:00
|
|
|
}),
|
2019-10-29 12:55:15 +02:00
|
|
|
],
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-10-29 12:55:15 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|