Skip to content

Commit 6016211

Browse files
committed
Tweak margins
Signed-off-by: Glenn Lewis <[email protected]>
1 parent e7e7455 commit 6016211

File tree

1 file changed

+18
-12
lines changed
  • examples/make-address-labels

1 file changed

+18
-12
lines changed

examples/make-address-labels/main.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import (
3333
)
3434

3535
const (
36-
pdfMarginMM = 10
36+
pdfXMarginMM = 15
37+
pdfYMarginMM = 25
3738
pdfDPI = 300
3839
mmPerInch = 25.4
3940
dpmm = pdfDPI / mmPerInch // pixels/mm for 300DPI images
@@ -71,21 +72,13 @@ func process(filename string) {
7172
addresses := strings.Split(string(buf), "\n\n")
7273
log.Printf("Got %v addresses from %v", len(addresses), filename)
7374

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()
8376
_, lineHeight1 := p.GetFontSize()
8477

8578
for i, label := range addresses {
8679
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
8982
lines := strings.Split(label, "\n")
9083
for j, line := range lines {
9184
p.SetXY(x, y+(lineHeight1+1.0)*float64(j))
@@ -99,6 +92,19 @@ func process(filename string) {
9992
log.Printf("Wrote %v", pdfFilename)
10093
}
10194

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+
102108
func must(err error) {
103109
if err != nil {
104110
log.Fatal(err)

0 commit comments

Comments
 (0)