@@ -33,7 +33,8 @@ import (
33
33
)
34
34
35
35
const (
36
- pdfMarginMM = 10
36
+ pdfXMarginMM = 15
37
+ pdfYMarginMM = 25
37
38
pdfDPI = 300
38
39
mmPerInch = 25.4
39
40
dpmm = pdfDPI / mmPerInch // pixels/mm for 300DPI images
@@ -71,21 +72,13 @@ func process(filename string) {
71
72
addresses := strings .Split (string (buf ), "\n \n " )
72
73
log .Printf ("Got %v addresses from %v" , len (addresses ), filename )
73
74
74
- p := fpdf .NewCustom (& fpdf.InitType {
75
- UnitStr : "mm" ,
76
- Size : fpdf.SizeType {Wd : widthMM , Ht : heightMM },
77
- })
78
- p .AddPage ()
79
- p .AddFontFromBytes (font1Family , "" , BalsamiqSansRegularJSON , BalsamiqSansRegularZ )
80
- p .SetAutoPageBreak (false , 0 )
81
- p .SetTextColor (0 , 0 , 0 )
82
- p .SetFont (font1Family , "" , 10 )
75
+ p := newPage ()
83
76
_ , lineHeight1 := p .GetFontSize ()
84
77
85
78
for i , label := range addresses {
86
79
nx , ny := i % numLabelsX , i / numLabelsX
87
- x := pdfMarginMM + float64 (nx )* widthMM / numLabelsX
88
- y := float64 (ny ) * (heightMM - pdfMarginMM ) / numLabelsY
80
+ x := pdfXMarginMM + float64 (nx )* ( widthMM - pdfXMarginMM ) / numLabelsX
81
+ y := 2 * lineHeight1 + float64 (ny )* (heightMM - pdfYMarginMM ) / numLabelsY
89
82
lines := strings .Split (label , "\n " )
90
83
for j , line := range lines {
91
84
p .SetXY (x , y + (lineHeight1 + 1.0 )* float64 (j ))
@@ -99,6 +92,19 @@ func process(filename string) {
99
92
log .Printf ("Wrote %v" , pdfFilename )
100
93
}
101
94
95
+ func newPage () fpdf.Pdf {
96
+ p := fpdf .NewCustom (& fpdf.InitType {
97
+ UnitStr : "mm" ,
98
+ Size : fpdf.SizeType {Wd : widthMM , Ht : heightMM },
99
+ })
100
+ p .AddPage ()
101
+ p .AddFontFromBytes (font1Family , "" , BalsamiqSansRegularJSON , BalsamiqSansRegularZ )
102
+ p .SetAutoPageBreak (false , 0 )
103
+ p .SetTextColor (0 , 0 , 0 )
104
+ p .SetFont (font1Family , "" , 10 )
105
+ return p
106
+ }
107
+
102
108
func must (err error ) {
103
109
if err != nil {
104
110
log .Fatal (err )
0 commit comments