-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (65 loc) · 1.11 KB
/
main.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
package main
import (
"fmt"
"github.com/jung-kurt/gofpdf"
)
type row struct {
leftCol string
rightCol string
}
type table struct {
rows []row
}
func generatePdf(tables []table) {
pdf := gofpdf.New("L", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
for idx, tableObj := range tables {
pos := float64((90 * idx) + 10)
if idx != 0 {
pos += 10
}
pdf.Rect(pos, 10, 90, 80, "")
pdf.SetY(10)
for _, row := range tableObj.rows {
pdf.SetX(pos)
pdf.CellFormat(45, 10, row.leftCol, "1", 0, "L", false, 0, "")
pdf.CellFormat(45, 10, row.rightCol, "1", 0, "L", false, 0, "")
pdf.Ln(-1)
}
}
_ = pdf.OutputFileAndClose("output/hello.pdf")
}
func main() {
boxes := []table{
table{
[]row{
row{
leftCol: "first",
rightCol: "second",
},
row{
leftCol: "third",
rightCol: "forth",
},
row{
leftCol: "more", rightCol: "data",
},
},
},
table{
[]row{
row{
leftCol: "x",
rightCol: "y",
},
row{
leftCol: "z",
rightCol: "q",
},
},
},
}
generatePdf(boxes)
fmt.Println("success")
}