-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.ts
More file actions
65 lines (53 loc) · 1.95 KB
/
Copy pathsimple.ts
File metadata and controls
65 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { RichTextDocumentBuilder, pt } from "../../lib"
const builder = new RichTextDocumentBuilder()
// Add some colors
builder.withColor("red", { red: 255, green: 0, blue: 0 })
builder.withColor("blue", { red: 0, green: 0, blue: 255 })
builder.withColor("gray", { red: 128, green: 128, blue: 128 })
// Add some fonts
builder.withFont("arial", { name: "Arial", family: "swiss" })
// Create a new section
builder.withSection((section) => {
// Create a centered title
section.body.withTitle("demo")
// Create a description paragraph
section.body.withText("This is a simple RTF document created with the new builder pattern API.").closeParagraph()
// Create a paragraph with mixed formatting
section.body.withText(
"Here is some ",
{ bold: true, colorAlias: "red" },
"bold red text",
{},
" and some ",
{ italic: true, colorAlias: "blue" },
"italic blue text",
{},
"."
)
// Create a simple table using the builder pattern
section.body.withSimpleTable(["Table row", "with two columns"], [["Second row", "and the second column"]])
// Create a paragraph with borders
section.body.withParagraph((p) => {
p.border("all", { width: pt(2), colorAlias: "red" }).withText("This paragraph has a red border.")
})
// Create a table with borders
section.body.withTable((table) => {
table.border("all", { width: pt(1) })
table.cellPadding({ top: pt(5), right: pt(5), bottom: pt(5), left: pt(5) })
table.withHeaderRow((row) => {
row.withCell((cell) => cell.withText({ bold: true }, "Header 1"))
row.withCell((cell) => cell.withText({ bold: true }, "Header 2"))
})
table.withRow((row) => {
row.withCell((cell) => {
cell.border("all", { width: pt(1), colorAlias: "blue", style: "dotted" })
cell.withText("Dotted blue border")
})
row.withCell((cell) => {
cell.backgroundColor("gray")
cell.withText("Shaded cell")
})
})
})
})
export default builder