3
25
Fork
You've already forked fpdf
10

Unable to set header and footer with template #56

Open
opened 2024年01月06日 15:17:07 +01:00 by darylhjd · 0 comments
darylhjd commented 2024年01月06日 15:17:07 +01:00 (Migrated from github.com)
Copy link

Using this code:

funcmain(){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!

Using this code: ```golang 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 in to join this conversation.
No Branch/Tag specified
main
v0.12.0
v0.11.1
v0.10.0
v0.11.0
v0.9.0
v0.8.0
v0.7.0
v0.6.0
v0.5.0
v1.4.3
v0.4.1
v0.4.0
v0.3.1
v0.3.0
v0.2.0
v0.1.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
go-pdf/fpdf#56
Reference in a new issue
go-pdf/fpdf
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?