go-pdf/fpdf

How to add a page count at the bottom of Page

nenodias opened this issue · 1 comments

Hi, I was trying to add a page count at the bottom of the page, as the other implementation of fpdf works, by using pdf.SetY(-15) and therefore adding a cell.

But a new page is added and the {nb} is not interpolated.

package main

import (
	"fmt"

	"github.com/go-pdf/fpdf"
)

func main() {
	pdf := fpdf.New("P", "mm", "A4", "")
	tr := pdf.UnicodeTranslatorFromDescriptor("")
	pdf.AddPage()
	pdf.SetFont("Arial", "B", 16)
	pdf.Cell(40, 10, tr("Olá, mundo"))
	pdf.SetY(-15)
	pdf.SetFont("Arial", "I", 8)
	pageNum := fmt.Sprintf("%d/{nb}", pdf.PageNo())
	pdf.CellFormat(0, 10, pageNum, "", 0, "C", false, 0, "")
	err := pdf.OutputFileAndClose("hello.pdf")
	if err != nil {
		panic(err.Error())
	}
}

To interpolate {nb} had to force by using pdf.AliasNbPages("{nb}"), but even though another page was added.

image

sbinet commented

See the example of AddPage that uses SetFooterFunc :
https://pkg.go.dev/github.com/go-pdf/fpdf#example-Fpdf.AddPage

(feel free to reopen if that didn't help)