-
Notifications
You must be signed in to change notification settings - Fork 0
/
footer.go
45 lines (38 loc) · 1002 Bytes
/
footer.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
/*
Package invoice_generator
Copyright 2021 @chunvv. All Rights Reserved.
Created by Trung Vu on AD 2021/07/10.
*/
package invoice_generator
import (
"fmt"
"github.com/creasty/defaults"
"github.com/jung-kurt/gofpdf"
)
func (hf *HeaderFooter) applyFooter(d *Document, pdf *gofpdf.Fpdf) error {
if err := defaults.Set(hf); err != nil {
return err
}
if !hf.UseCustomFunc {
pdf.SetFooterFunc(func() {
currentY := pdf.GetY()
currentX := pdf.GetX()
pdf.SetTopMargin(HeaderMarginTop)
pdf.SetY(287 - HeaderMarginTop)
pdf.SetFont("deja", "", hf.FontSize)
_, lineHt := pdf.GetFontSize()
html := pdf.HTMLBasicNew()
html.Write(lineHt, hf.Text)
if hf.Pagination {
pdf.AliasNbPages("")
pdf.SetY(287 - HeaderMarginTop - 8)
pdf.SetX(195)
pdf.CellFormat(10, 5, fmt.Sprintf("Page %d/{nb}", pdf.PageNo()), "0", 0, "R", false, 0, "")
}
pdf.SetY(currentY)
pdf.SetX(currentX)
pdf.SetMargins(BaseMargin, BaseMarginTop, BaseMargin)
})
}
return nil
}