When fpdf2 renders page-count aliases created with alias_nb_pages(), layout first reserves horizontal space for the alias placeholder. Later, during output generation, the placeholder is replaced with the final total page count.
Today the replacement alignment is implicit:
- regular / non-text-shaped text keeps the existing inline behavior, effectively left-aligned in the reserved space
- text-shaped rendering centers the replacement inside the reserved space to keep surrounding shaped text stable
It would be useful to expose this as an explicit user choice.
Proposed API
pdf.alias_nb_pages(alias="{nb}", align="C")
Where align could support the usual horizontal alignment values (from enums.py/Align):
Align.L: left-align replacement text inside the reserved alias space
Align.C: center replacement text inside the reserved alias space
Align.R: right-align replacement text inside the reserved alias space
Expected behavior
The alias string should continue to define the reserved layout width. For example, users who expect a larger total page count can use a wider alias to reserve more space:
pdf.alias_nb_pages(alias="{total_pages}", align="R")
Then every occurrence of {total_pages} reserves the width of {total_pages}, and the final page count is rendered right-aligned inside that reserved area.
This would make page-count substitution behavior explicit and consistent across regular text and text-shaped text, while preserving backward compatibility by keeping the current default alignment unchanged.
It also gives users a clean way to control visual placement of substitution text.
When fpdf2 renders page-count aliases created with
alias_nb_pages(), layout first reserves horizontal space for the alias placeholder. Later, during output generation, the placeholder is replaced with the final total page count.Today the replacement alignment is implicit:
It would be useful to expose this as an explicit user choice.
Proposed API
Where align could support the usual horizontal alignment values (from enums.py/Align):
Align.L: left-align replacement text inside the reserved alias space
Align.C: center replacement text inside the reserved alias space
Align.R: right-align replacement text inside the reserved alias space
Expected behavior
The alias string should continue to define the reserved layout width. For example, users who expect a larger total page count can use a wider alias to reserve more space:
pdf.alias_nb_pages(alias="{total_pages}", align="R")Then every occurrence of {total_pages} reserves the width of {total_pages}, and the final page count is rendered right-aligned inside that reserved area.
This would make page-count substitution behavior explicit and consistent across regular text and text-shaped text, while preserving backward compatibility by keeping the current default alignment unchanged.
It also gives users a clean way to control visual placement of substitution text.