Skip to content

Add ability to configure thousands separator for formatPageNumber and formatTOCPageNumber #861

@kunalray1993

Description

@kunalray1993

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions