Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set header and footer with template #56

Open
darylhjd opened this issue Jan 6, 2024 · 0 comments
Open

Unable to set header and footer with template #56

darylhjd opened this issue Jan 6, 2024 · 0 comments

Comments

@darylhjd
Copy link

darylhjd commented Jan 6, 2024

Using this code:

func main() {
	pdf := fpdf.New(fpdf.OrientationPortrait, fpdf.UnitMillimeter, fpdf.PageSizeA4, "")
	pdf.SetFont("Arial", "", 13)

	contentPageTemplate := pdf.CreateTemplate(func(tpl *fpdf.Tpl) {
		tpl.SetHeaderFuncMode(func() {
			tpl.SetY(5)
			tpl.SetFont("Arial", "B", 15)
			tpl.Cell(80, 0, "")
			tpl.CellFormat(30, 10, "Title", "1", 0, "C", false, 0, "")
			tpl.Ln(20)
			tpl.CellFormat(30, 10, "Class Report", "", 0, fpdf.AlignCenter, false, 0, "")
		}, true)
		tpl.SetFooterFunc(func() {
			tpl.SetY(-15)
			tpl.SetFont("Arial", "I", 13)
			tpl.CellFormat(0, 10, fmt.Sprintf("Page %d/{nb}", tpl.PageNo()),
				"", 0, "C", false, 0, "")
		})
	})

	pdf.AliasNbPages("")
	pdf.AddPage()
	pdf.CellFormat(0, 10, "This is the front cover", "", 0, fpdf.AlignCenter, false, 0, "")
	pdf.AddPage()
	pdf.UseTemplate(contentPageTemplate)
	pdf.CellFormat(0, 10, "This is the a content page with header and footer", "", 0, fpdf.AlignCenter, false, 0, "")

	log.Println(pdf.PageCount())

	pdf.OutputFileAndClose("test.pdf")
}

I am not able to add a header and footer on the second page. Is this the wrong way to do it?

Also, I am not sure if the authors of fpdf are open to using the Discussions page for this repo. I was looking for it to ask the question but it seems it is only possible for me to do so via opening an issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant