/
generate_pdf.go
102 lines (90 loc) · 1.87 KB
/
generate_pdf.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
package main
import (
"fmt"
"strconv"
"time"
"github.com/johnfercher/maroto/pkg/color"
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
)
func main() {
m := pdf.NewMaroto(consts.Portrait, consts.A4)
m.SetPageMargins(10, 15, 10)
m.SetAliasNbPages("{nb}")
m.SetFirstPageNb(1)
m.RegisterHeader(func() {
m.Row(15, func() {
m.Col(9, func() {
m.Text("E-mail Breakdown", props.Text{
Size: 15,
Top: 1,
Align: consts.Center,
Style: consts.Bold,
})
})
m.Col(3, func() {
m.Text(time.Now().Format("January 2, 2006"), props.Text{
Size: 10,
Top: 7,
Align: consts.Center,
Family: consts.Courier,
})
})
})
})
m.Line(1.0,
props.Line{
Color: color.Color{0, 0, 0},
Width: 1.0,
},
)
m.Row(20, func() {
m.Col(12, func() {
m.Text("Parsed Headers", props.Text{
Size: 12,
Top: 8,
//Align: consts.Center,
Family: consts.Helvetica,
Color: color.Color{150, 0, 0},
})
})
})
m.TableList(
[]string{"Header", "Value"},
[][]string{
[]string{"From", "anonymous@gmail.com"},
[]string{"To", "johnwick@gmail.com"},
[]string{"Sender", "anonymous@gmail.com"},
[]string{"Message-ID", "141lkjdpqrfe41041734dzaf"},
},
props.TableList{
HeaderProp: props.TableListContent{
Style: consts.BoldItalic,
Size: 11,
Color: color.Color{0, 100, 150},
},
ContentProp: props.TableListContent{
Style: consts.Normal,
Size: 11,
},
//Align: consts.Center,
Line: true,
},
)
m.RegisterFooter(func() {
m.Row(10, func() {
m.Col(12, func() {
m.Text(strconv.Itoa(m.GetCurrentPage())+"/{nb}", props.Text{
Align: consts.Right,
Size: 10,
})
})
})
})
err := m.OutputFileAndClose("./learn.pdf")
if err != nil {
fmt.Printf("%s\n", err.Error())
return
}
}