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

36 lines
1.0 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
const doc = new Document();
2019-08-06 21:37:33 +01:00
doc.addSection({
headers: {
default: new Header({
children: [
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun({
text: "Hello World",
color: "red",
bold: true,
size: 24,
font: {
name: "Garamond",
},
highlight: "yellow",
}),
],
}),
],
}),
},
children: [],
});
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);
});