Skip to content

Commit

Permalink
Fix draw last footer (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher authored Apr 8, 2022
1 parent 9e1d5a6 commit 303a313
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ examples:
go run internal/examples/qrgrid/main.go
go run internal/examples/sample1/main.go
go run internal/examples/textgrid/main.go
go run internal/examples/utfsample/main.go
go run internal/examples/zpl/main.go
go run internal/examples/zpl/main.go
go run internal/examples/utfsample/main.go
Binary file modified internal/examples/pdfs/barcodegrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/billing.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/certificate.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/customsize.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/dmgrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/imagegrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/qrgrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/sample1.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/textgrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/zpl.pdf
Binary file not shown.
6 changes: 4 additions & 2 deletions internal/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func NewMath(pdf fpdf.Fpdf) *math {
// GetRectCenterColProperties define Width, Height, X Offset and Y Offset
// to and rectangle (QrCode, Barcode, Image) be centralized inside a cell.
func (s *math) GetRectCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64,
xColOffset float64, percent float64) (x float64, y float64, w float64, h float64) {
xColOffset float64, percent float64,
) (x float64, y float64, w float64, h float64) {
percent /= 100.0
left, top, _, _ := s.pdf.GetMargins()

Expand Down Expand Up @@ -68,7 +69,8 @@ func (s *math) GetRectCenterColProperties(imageWidth float64, imageHeight float6

// GetRectNonCenterColProperties define Width, Height to and rectangle (QrCode, Barcode, Image) inside a cell.
func (s *math) GetRectNonCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64,
xColOffset float64, prop props.Rect) (x float64, y float64, w float64, h float64) {
xColOffset float64, prop props.Rect,
) (x float64, y float64, w float64, h float64) {
percent := prop.Percent / maxPercent
left, top, _, _ := s.pdf.GetMargins()

Expand Down
1 change: 1 addition & 0 deletions pkg/pdf/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func ExamplePdfMaroto_RegisterFooter() {
// It is important to remember that it is recommended to create Row's and
// Col's if necessary.
// You have to register the footer immediately after the Maroto
// All footers will be rendered at the bottom of all pages

m := pdf.NewMaroto(consts.Portrait, consts.A4)

Expand Down
7 changes: 7 additions & 0 deletions pkg/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,13 @@ func (s *PdfMaroto) drawLastFooter() {
_, top, _, bottom := s.Pdf.GetMargins()

if s.offsetY+s.footerHeight < pageHeight-bottom-top {
totalOffsetY := int(s.offsetY + s.footerHeight)
maxOffsetPage := int(pageHeight - bottom - top)

s.Row(float64(maxOffsetPage-totalOffsetY), func() {
s.ColSpace(12)
})

s.headerFooterContextActive = true
s.footerClosure()
s.headerFooterContextActive = false
Expand Down
3 changes: 2 additions & 1 deletion pkg/pdf/pdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,8 @@ func TestFpdfMaroto_OutputFileAndClose(t *testing.T) {

func newMarotoTest(fFpdf *mocks.Fpdf, math *mocks.Math, font *mocks.Font, text *mocks.Text,
signature *mocks.Signature, image *mocks.Image, code *mocks.Code, tableList *mocks.TableList,
line *mocks.Line) pdf.Maroto {
line *mocks.Line,
) pdf.Maroto {
m := &pdf.PdfMaroto{
Pdf: fFpdf,
Math: math,
Expand Down

0 comments on commit 303a313

Please sign in to comment.