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

67 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

2019-08-06 23:08:21 +01:00
// Shading 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, ShadingType, 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",
color: "FF0000",
2021-03-19 20:53:56 +00:00
bold: true,
size: 24,
font: {
name: "Garamond",
},
shading: {
2021-05-29 05:51:06 +03:00
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
2021-03-19 20:53:56 +00:00
color: "00FFFF",
fill: "FF0000",
},
}),
],
}),
new Paragraph({
2019-08-06 23:08:21 +01:00
shading: {
2021-05-29 05:51:06 +03:00
type: ShadingType.DIAGONAL_CROSS,
2019-08-06 21:37:33 +01:00
color: "00FFFF",
fill: "FF0000",
},
2021-03-19 20:53:56 +00:00
children: [
new TextRun({
text: "Hello World for entire paragraph",
}),
],
2019-08-06 21:37:33 +01:00
}),
],
}),
2021-03-19 20:53:56 +00:00
},
children: [
2020-10-28 01:05:31 +00:00
new Paragraph({
children: [
new TextRun({
2021-03-19 20:53:56 +00:00
emboss: true,
text: "Embossed text - hello world",
}),
new TextRun({
imprint: true,
text: "Imprinted text - hello world",
2020-10-28 01:05:31 +00:00
}),
],
}),
2019-08-06 21:37:33 +01:00
],
2021-03-19 20:53:56 +00:00
},
2021-03-13 20:23:15 +00:00
],
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);
});