Files
docx-js/demo/45-highlighting-text.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-08-06 23:08:21 +01:00
// Highlighting text
// Import from 'docx' rather than '../build' if you install from npm
2019-08-05 13:42:45 +03:00
import * as fs from "fs";
2019-08-06 21:37:33 +01:00
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
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",
color: "red",
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);
});