Files
docx-js/demo/56-background-color.ts

35 lines
916 B
TypeScript
Raw Normal View History

2020-10-27 01:54:40 +00:00
// Change background colour of whole document
2023-06-05 00:33:43 +01:00
2020-10-27 01:54:40 +00:00
import * as fs from "fs";
2023-06-05 00:33:43 +01:00
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
2020-10-27 01:54:40 +00:00
const doc = new Document({
background: {
color: "C45911",
},
2021-03-19 20:53:56 +00:00
sections: [
{
properties: {},
2020-10-27 01:54:40 +00: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({
2022-10-29 15:10:02 +01:00
children: [new Tab(), "Github is the best"],
2021-03-19 20:53:56 +00:00
bold: true,
}),
],
2020-10-27 01:54:40 +00:00
}),
],
2021-03-19 20:53:56 +00:00
},
2020-10-27 01:54:40 +00:00
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});