-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
example_test.go
144 lines (105 loc) · 3.21 KB
/
example_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package maroto_test
import (
"log"
"github.com/johnfercher/maroto/v2/pkg/components/text"
"github.com/johnfercher/maroto/v2"
"github.com/johnfercher/maroto/v2/pkg/components/code"
"github.com/johnfercher/maroto/v2/pkg/components/page"
"github.com/johnfercher/maroto/v2/pkg/config"
)
// ExampleNew demonstrates how to create a maroto instance.
func ExampleNew() {
// optional
b := config.NewBuilder()
cfg := b.Build()
m := maroto.New(cfg) // cfg is an optional
// Do things and generate
_, _ = m.Generate()
}
// ExampleNewMetricsDecorator demonstrates how to create a maroto metrics decorator instance.
func ExampleNewMetricsDecorator() {
// optional
b := config.NewBuilder()
cfg := b.Build()
mrt := maroto.New(cfg) // cfg is an optional
m := maroto.NewMetricsDecorator(mrt) // decorator of maroto
// Do things and generate
_, _ = m.Generate()
}
// ExampleMaroto_AddPages demonstrates how to add a new page in maroto.
func ExampleMaroto_AddPages() {
m := maroto.New()
p := page.New()
p.Add(code.NewBarRow(10, "barcode"))
m.AddPages(p)
// Do things and generate
}
// ExampleMaroto_AddRows demonstrates how to add new rows in maroto.
func ExampleMaroto_AddRows() {
m := maroto.New()
m.AddRows(
code.NewBarRow(12, "barcode"),
text.NewRow(12, "text"),
)
// Do things and generate
}
// ExampleMaroto_AddRow demonstrates how to add a new row in maroto.
func ExampleMaroto_AddRow() {
m := maroto.New()
m.AddRow(10, text.NewCol(12, "text"))
// Do things and generate
}
// ExampleMaroto_FitlnCurrentPage demonstrate how to check if the new line fits on the current page
func ExampleMaroto_FitlnCurrentPage() {
m := maroto.New()
m.FitlnCurrentPage(12)
// Do things and generate
}
// ExampleMaroto_FitlnCurrentPage demonstrate how to check if the new line fits on the current page
func ExampleMaroto_GetCurrentConfig() {
m := maroto.New()
m.GetCurrentConfig()
// Do things and generate
}
// ExampleMaroto_RegisterHeader demonstrates how to register a header to me added in every new page.
// An error is returned if the area occupied by the header is greater than the page area.
func ExampleMaroto_RegisterHeader() {
m := maroto.New()
err := m.RegisterHeader(
code.NewBarRow(12, "barcode"),
text.NewRow(12, "text"))
if err != nil {
panic(err)
}
// Do things and generate
}
// ExampleMaroto_RegisterFooter demonstrates how to register a footer to me added in every new page.
// An error is returned if the area occupied by the footer is greater than the page area.
func ExampleMaroto_RegisterFooter() {
m := maroto.New()
err := m.RegisterFooter(
code.NewBarRow(12, "barcode"),
text.NewRow(12, "text"))
if err != nil {
panic(err)
}
// Do things and generate
}
// ExampleMaroto_Generate demonstrates how to generate a file.
func ExampleMaroto_Generate() {
m := maroto.New()
// Add rows, pages and etc.
doc, err := m.Generate()
if err != nil {
log.Fatal(err)
}
// You can retrieve as Base64, Save file, Merge with another file or GetReport.
_ = doc.GetBytes()
}
// ExampleMarotoGetStruct demonstrates how to get maroto component tree
func ExampleMaroto_GetStructure() {
m := maroto.New()
m.AddRow(40, text.NewCol(12, "text"))
m.GetStructure()
// Do things and generate
}