-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator_test.go
127 lines (113 loc) · 4.36 KB
/
generator_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package pdf_test
import (
"bytes"
"os"
"testing"
"time"
"rogchap.com/pdf"
"golang.org/x/exp/trace"
)
type testDoc struct{}
func (d *testDoc) Build(doc *pdf.Doc) {
doc.Author = "rogchap"
doc.Title = "Kitchen Sink"
doc.Creation = time.Now()
// doc.Page(func(page *pdf.Page) {
// // page.PageSize(pdf.PageSizeA4Landscape)
// page.MarginVH(75)
// // page.Color("#f00")
//
// page.Header().Padding(0, 0, 0, 50).AlignCenter().Text("Header").Color("#f00")
// page.Footer().
// Padding(0, 50, 0, 0).
// AlignRight().
// StyledBorder(pdf.BorderStyle{
// Right: 0.5,
// Bottom: 0.5,
// Top: 0.5,
// Left: 0.5,
// RadiusTopLeft: 10,
// RadiusBottomRight: 10,
// Color: "#aaa",
// }).
// Padding(10, 10, 10, 10).
// TextBlock(func(text *pdf.TextBlock) {
// text.Span("Page ")
// text.CurrentPage()
// })
//
// page.Content().
// // Background("#020").
// VStack(func(stack *pdf.VStack) {
// stack.Space(50)
//
// stack.Item().Text(textCopy).FontSize(24)
// stack.Item().Text(textCopy).FontSize(34).Italic(true)
// stack.Item().Text(textCopy).FontSize(44)
//
// stack.Item().HStack(func(hstack *pdf.HStack) {
// hstack.RelativeItem(1).ImageFile("testdata/park1.jpg")
// hstack.RelativeItem(1).AlignCenter().ImageFile("testdata/park2.jpg")
// hstack.RelativeItem(1).AlignRight().ImageFile("testdata/park3.jpg")
// })
//
// stack.Item().Text(textCopy).FontSize(54).LineHeight(1.5)
// stack.Item().Text(textCopy).FontSize(64)
// stack.Item().Text(textCopy).FontSize(64).FontWeight(pdf.FontWeightLight)
// stack.Item().Text(textCopy).FontSize(64)
// stack.Item().PageBreak()
// stack.Item().Text(textCopy).FontSize(54)
// stack.Item().Text(textCopy).FontSize(54).Bold()
// stack.Item().Text(textCopy).FontSize(54)
// stack.Item().AlignCenter().ImageFile("testdata/park4.jpg")
// stack.Item().Text(textCopy).FontSize(54)
// stack.Item().Text(textCopy).FontSize(54).FontFamily("Times New Roman")
// stack.Item().Text(textCopy).FontSize(54)
// stack.Item().AlignCenter().Text("THE END").FontWeight(pdf.FontWeightBlack).FontSize(74).Color("#df00fa")
// })
// })
// doc.Page(func(page *pdf.Page) {
// page.PageSize(pdf.PageSizeA4Landscape)
// page.MarginVH(75)
//
// page.Content().HStack(func(hstack *pdf.HStack) {
// hstack.Space(50)
//
// hstack.RelativeItem(1).Text(textCopy).FontSize(36)
// hstack.RelativeItem(1).Text(textCopy).FontSize(62)
// })
// })
doc.Page(func(page *pdf.Page) {
page.MarginVH(75)
page.Content().VStack(func(vstack *pdf.VStack) {
vstack.Item().
Border(4, 10, "#000").
Table(func(table *pdf.Table) {
table.RelCol(1)
table.RelCol(1)
table.RelCol(1)
table.Cell().Padding(10, 10, 10, 10).Text("Cell 1").FontSize(65)
table.Cell().Border(1, 0, "#000").Padding(10, 10, 10, 10).Text("Cell 2").FontSize(65)
table.Cell().Text("Cell 3").FontSize(65)
table.Cell().Border(1, 0, "#000").Text("Cell 4").FontSize(65)
table.Cell().Border(1, 0, "#000").Text("Cell 5").FontSize(65)
table.Cell().Border(1, 0, "#000").Text("Cell 6").FontSize(65)
table.Cell().StyledBorder(pdf.BorderStyle{
Right: 1,
Color: "#000",
}).Text("Cell 7").FontSize(65)
})
})
})
}
func TestGenerator(t *testing.T) {
fr := trace.NewFlightRecorder()
fr.Start()
f, _ := os.Create("output.pdf")
defer f.Close()
pdf.Generate(f, &testDoc{})
var b bytes.Buffer
fr.WriteTo(&b)
os.WriteFile("trace.out", b.Bytes(), 0o755)
}
var textCopy = "Welcome to the bustling city streets, where the rhythm of life never seems to slow down. 🏙️From the early morning rush to the late-night revelry, there's always something happening around every corner. The aroma of freshly brewed coffee wafts through the air as people hurry to catch their morning commute 🚶♂️🚶♀️, while street performers entertain crowds with their mesmerizing tunes. 世欢迎来到丛林. As the sun sets, the cityscape transforms into a kaleidoscope of neon lights, painting the sky with vibrant hues. 🌆Amidst the hustle and bustle, friendships are forged, dreams are chased, and love finds its way into the most unexpected places. So, take a stroll down these lively streets and let the city's energy sweep you off your feet. 🌟💫"