Skip to content

Add configurable thousands separator for page number formatting#862

Open
kunalray1993 wants to merge 2 commits intotecnickcom:mainfrom
kunalray1993:configurable-thousands-separator
Open

Add configurable thousands separator for page number formatting#862
kunalray1993 wants to merge 2 commits intotecnickcom:mainfrom
kunalray1993:configurable-thousands-separator

Conversation

@kunalray1993
Copy link
Copy Markdown

This PR addresses the issue reported here: #861

Overview

This pull request introduces the ability to configure the thousands separator used by TCPDF_STATIC::formatPageNumber and TCPDF_STATIC::formatTOCPageNumber.

Previously, these functions used a hard-coded dot (.) as the thousands separator, which caused issues for users in locales that use different conventions (comma, space, or no separator). This PR adds flexibility by allowing developers to set the separator at runtime.

Background

The original implementation:

public static function formatPageNumber($num) {
    return number_format((float)$num, 0, '', '.');
}

public static function formatTOCPageNumber($num) {
    return number_format((float)$num, 0, '', '.');
}

This forced all page numbers and TOC entries to use a dot separator regardless of locale. The enhancement makes the formatting customizable without modifying core files.

What This PR Adds

  • A new static property:
    TCPDF_STATIC::$thousands_separator
  • A setter method:
    TCPDF_STATIC::setThousandsSeparator($separator)
  • Updated logic in:
    TCPDF_STATIC::formatPageNumber
    TCPDF_STATIC::formatTOCPageNumber
    to use the configurable separator.

Benefits

  • Proper internationalization/localization support
  • No need to patch or fork TCPDF
  • Backward-compatible (default separator remains .)
  • Gives developers full control over number formatting in generated PDFs

Example Usage

$pdf = new TCPDF();

...
$pdf->setThousandsSeparator(',');
...

Backward Compatibility

  • Default behavior unchanged
  • No API breakage
  • Fully optional new feature

Additional Notes

Happy to update the PR if maintainers prefer an alternative naming convention or a broader locale configuration approach.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 7, 2026

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

3 participants