TCPDF icon indicating copy to clipboard operation
TCPDF copied to clipboard

Add ability to configure thousands separator for `formatPageNumber` and `formatTOCPageNumber`

Open kunalray1993 opened this issue 7 months ago • 1 comments

Description

In the static functions TCPDF_STATIC::formatPageNumber and TCPDF_STATIC::formatTOCPageNumber, the thousands separator is currently hard-coded as a dot (.):

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

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

However, number formatting conventions vary by country or user preference. For example:

  • Many locales use a comma (,) as the thousands separator
  • Some locales use a space ( )
  • Some users may not want any separator at all

Since TCPDF is used globally, having a fixed separator limits customization and forces developers to manually override or modify the library.

Proposed Enhancement

Introduce a configurable thousands separator that can be set at runtime, for example via:

  • A new private static property in TCPDF_STATIC
  • A new constant or class setting
  • A setter method such as TCPDF_STATIC::setThousandsSeparator($separator)

This value should be used internally by:

  • TCPDF_STATIC::formatPageNumber
  • TCPDF_STATIC::formatTOCPageNumber
  • Any other related formatting routines

Why This Matters

  • Allows localization and internationalization of generated PDFs
  • Avoids the need to patch or fork TCPDF just to change number formatting
  • Enhances flexibility for developers generating documents with custom formatting requirements

Suggested Code Adjustment

Example idea (not final):

private static $thousands_separator = '.';

public static function setThousandsSeparator($separator) {
    self::$thousands_separator = $separator;
}

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

kunalray1993 avatar Apr 07 '26 09:04 kunalray1993

Thank you for reporting this. TCPDF 6 is now a legacy project and is officially deprecated, so no further fixes or features will be merged into this repository. As part of this transition, we are closing older issues. Please migrate to tc-lib-pdf and, if the same problem still occurs there, open a new issue with updated reproduction steps. For more context, see the pinned announcement: Thank You - and the Future of TCPDF.

nicolaasuni avatar May 30 '26 18:05 nicolaasuni