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

Question: is it possible to render page number in the footer row? #495

Open
zirain opened this issue Nov 18, 2024 · 4 comments
Open

Question: is it possible to render page number in the footer row? #495

zirain opened this issue Nov 18, 2024 · 4 comments
Assignees
Labels
in analysis Analyzing if should be implemented new feature New feature or request

Comments

@zirain
Copy link

zirain commented Nov 18, 2024

pageNumber := props.PageNumber{
		Pattern: "{current}/{total}",
		Place:   props.RightBottom,
		Size:    footerFontSize,
	}
	cfg := config.NewBuilder().
		WithMaxGridSize(maxGridSize).
		WithPageNumber(pageNumber).
		Build()
	m := maroto.New(cfg)

	// footer
	footerRow := row.New().Add(
		text.NewCol(16, "Report", props.Text{
			Top:   footTop,
			Size:  footerFontSize,
			Align: align.Center,
		}),
		text.NewCol(2, "", props.Text{ // is it possible to render page number here?
			Top:   footTop,
			Size:  footerFontSize,
			Align: align.Center,
		}),
	).WithStyle(footerRowStyle)
	_ = m.RegisterFooter(footerRow)
@Fernando-hub527 Fernando-hub527 added the question Further information is requested label Nov 29, 2024
@Fernando-hub527 Fernando-hub527 self-assigned this Nov 29, 2024
@Fernando-hub527
Copy link
Collaborator

Fernando-hub527 commented Nov 29, 2024

Hello, sorry for the delay!
Maybe you could use a workaround to add the page number in the footer, but unfortunately, Maroto doesn't support that directly. Does adding the page number like this not work for your case?

@zirain
Copy link
Author

zirain commented Nov 29, 2024

@Fernando-hub527
I try that demo with:

package main

import (
	"log"

	"github.com/johnfercher/maroto/v2"
	"github.com/johnfercher/maroto/v2/pkg/components/row"
	"github.com/johnfercher/maroto/v2/pkg/components/text"
	"github.com/johnfercher/maroto/v2/pkg/config"
	"github.com/johnfercher/maroto/v2/pkg/consts/border"
	"github.com/johnfercher/maroto/v2/pkg/consts/fontfamily"
	"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"
	"github.com/johnfercher/maroto/v2/pkg/core"
	"github.com/johnfercher/maroto/v2/pkg/props"
)

func main() {
	m := GetMaroto()
	document, err := m.Generate()
	if err != nil {
		log.Fatal(err.Error())
	}

	err = document.Save("sample.pdf")
	if err != nil {
		log.Fatal(err.Error())
	}

	err = document.GetReport().Save("sample.txt")
	if err != nil {
		log.Fatal(err.Error())
	}
}

func GetMaroto() core.Maroto {
	pageNumber := props.PageNumber{
		Pattern: "Page {current} of {total}",
		Place:   props.RightBottom,
		Family:  fontfamily.Courier,
		Style:   fontstyle.Bold,
		Size:    9,
		Color: &props.Color{
			Red: 255,
		},
	}

	cfg := config.NewBuilder().
		WithDebug(true).
		WithPageNumber(pageNumber).
		Build()

	mrt := maroto.New(cfg)
	m := maroto.NewMetricsDecorator(mrt)

	// footer
	footerRow := row.New().Add(
		text.NewCol(4, "left"),
		text.NewCol(4, "center"),
		text.NewCol(4, "right"),
	).WithStyle(&props.Cell{
		BorderColor: &props.BlackColor,
		BorderType:  border.Top,
	})
	_ = m.RegisterFooter(footerRow)

	for i := 0; i < 15; i++ {
		m.AddRows(text.NewRow(20, "dummy text"))
	}

	return m
}
image

I expect page number show in the postion where right is.

@Fernando-hub527
Copy link
Collaborator

Hmmm, I understand!
Maybe we can add a margin property to pageNumber, that way we would have more freedom to define the position of the number. What do you think?

@Fernando-hub527 Fernando-hub527 added new feature New feature or request in analysis Analyzing if should be implemented and removed question Further information is requested labels Nov 30, 2024
@zirain
Copy link
Author

zirain commented Dec 1, 2024

Hmmm, I understand! Maybe we can add a margin property to pageNumber, that way we would have more freedom to define the position of the number. What do you think?

sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in analysis Analyzing if should be implemented new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants