Files
docx-js/demo/46-shading-text.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-08-06 23:08:21 +01:00
// Shading 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, ShadingType, 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",
},
2019-08-06 23:08:21 +01:00
shading: {
2019-08-06 21:37:33 +01:00
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
color: "00FFFF",
fill: "FF0000",
},
}),
],
}),
],
}),
},
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);
});