2019-08-06 23:08:21 +01:00
|
|
|
// Highlighting text
|
2023-06-05 00:33:43 +01:00
|
|
|
|
2019-08-05 13:42:45 +03:00
|
|
|
import * as fs from "fs";
|
2023-06-05 00:33:43 +01:00
|
|
|
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "docx";
|
2019-08-05 13:42:45 +03:00
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
default: new Header({
|
2019-08-06 21:37:33 +01:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
children: [
|
|
|
|
new TextRun({
|
|
|
|
text: "Hello World",
|
2021-05-24 08:42:34 +03:00
|
|
|
color: "FF0000",
|
2021-03-19 20:53:56 +00:00
|
|
|
bold: true,
|
|
|
|
size: 24,
|
|
|
|
font: {
|
|
|
|
name: "Garamond",
|
|
|
|
},
|
|
|
|
highlight: "yellow",
|
|
|
|
}),
|
|
|
|
],
|
2019-08-06 21:37:33 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
],
|
2019-08-06 21:37:33 +01:00
|
|
|
});
|
2019-08-05 13:42:45 +03:00
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2019-08-05 13:42:45 +03:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|