-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpdf.go
85 lines (67 loc) · 2.11 KB
/
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
package main
import (
"fmt"
"github.com/jung-kurt/gofpdf"
)
const (
TEXT_CHARNAME = iota
TEXT_CLASSANDLEVEL = iota
TEXT_BACKGROUND = iota
TEXT_PLAYERNAME = iota
TEXT_RACE = iota
TEXT_ALIGNMENT = iota
TEXT_XP = iota
)
type textInfo struct {
size float64
x float64
y float64
}
var textLocations = map[int]textInfo{
TEXT_CHARNAME: textInfo{size: 16, x: 20, y: 19},
TEXT_CLASSANDLEVEL: textInfo{size: 12, x: 92, y: 15},
TEXT_BACKGROUND: textInfo{size: 12, x: 131, y: 15},
TEXT_PLAYERNAME: textInfo{size: 12, x: 164, y: 15},
TEXT_RACE: textInfo{size: 12, x: 92, y: 25},
TEXT_ALIGNMENT: textInfo{size: 12, x: 131, y: 25},
TEXT_XP: textInfo{size: 12, x: 164, y: 25},
}
func initializePDF() *gofpdf.Fpdf {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "", 12)
return pdf
}
func addBackground(pdf *gofpdf.Fpdf, imagepath string) {
width, height, _ := pdf.PageSize(0)
pdf.ImageOptions(imagepath, 0, 0, width, height, false, gofpdf.ImageOptions{ImageType: "PNG", ReadDpi: true}, 0, "")
}
func setName(pdf *gofpdf.Fpdf, name string) {
addText(pdf, name, textLocations[TEXT_CHARNAME])
}
func setClassAndLevel(pdf *gofpdf.Fpdf, class string, level int) {
addText(pdf, fmt.Sprintf("%v %v", class, level), textLocations[TEXT_CLASSANDLEVEL])
}
func setBackground(pdf *gofpdf.Fpdf, background string) {
addText(pdf, background, textLocations[TEXT_BACKGROUND])
}
func setPlayerName(pdf *gofpdf.Fpdf, playerName string) {
addText(pdf, playerName, textLocations[TEXT_PLAYERNAME])
}
func setRace(pdf *gofpdf.Fpdf, race string) {
addText(pdf, race, textLocations[TEXT_RACE])
}
func setAlignment(pdf *gofpdf.Fpdf, alignment string) {
addText(pdf, alignment, textLocations[TEXT_ALIGNMENT])
}
func setXP(pdf *gofpdf.Fpdf, XP int) {
addText(pdf, fmt.Sprintf("%v", XP), textLocations[TEXT_XP])
}
func addText(pdf *gofpdf.Fpdf, txtStr string, info textInfo) {
pdf.SetXY(info.x, info.y)
pdf.SetFontSize(info.size)
pdf.Write(info.size, txtStr)
}
func generatePDF(pdf *gofpdf.Fpdf, filePath string) {
pdf.OutputFileAndClose(filePath)
}