0

Does mpdf has a setting somewhere to change the default numbering pattern? I'm trying to use {PAGENO} in a footer, and it always shows 1,2,3 etc rather than ۱،۲،۳ For now I can workaround by adding a str_replace in the aliasReplace function of Mpdf.php, but that isn't very clean.

  • 1
    Documentation. https://mpdf.github.io/reference/mpdf-variables/defaultpagenumstyle.html – Finwe Apr 11 '21 at 05:43
  • @Finwe - Many thanks for the documentation link - I hadn't spotted that one. It works for PAGENO but not for NBPG, so I can't say Page 1 of 3 in Persian using that parameter. Is there another parameter perhaps? – جیسن Apr 12 '21 at 15:53

1 Answers1

0

In the Mpdf.php file Edit the aliasReplace() function like this:

protected function aliasReplace($html, $PAGENO, $NbPgGp, $NbPg)
{

    $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
    $english = [ 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 ];
    $PAGENO= str_replace($english, $persian, $PAGENO);
    $NbPgGp= str_replace($english, $persian, $NbPgGp);
    $NbPg= str_replace($english, $persian, $NbPg);

    // Replaces for header and footer
    $html = str_replace('{PAGENO}', $PAGENO, $html);
    $html = str_replace($this->aliasNbPgGp, $NbPgGp, $html); // {nbpg}
    $html = str_replace($this->aliasNbPg, $NbPg, $html); // {nb}

    // Replaces for the body
    $html = str_replace(mb_convert_encoding('{PAGENO}', 'UTF-16BE', 'UTF-8'), mb_convert_encoding($PAGENO, 'UTF-16BE', 'UTF-8'), $html);
    $html = str_replace(mb_convert_encoding($this->aliasNbPgGp, 'UTF-16BE', 'UTF-8'), mb_convert_encoding($NbPgGp, 'UTF-16BE', 'UTF-8'), $html); // {nbpg}
    $html = str_replace(mb_convert_encoding($this->aliasNbPg, 'UTF-16BE', 'UTF-8'), mb_convert_encoding($NbPg, 'UTF-16BE', 'UTF-8'), $html); // {nb}

    // Date replace
    $html = preg_replace_callback('/\{DATE\s+(.*?)\}/', [$this, 'date_callback'], $html); // mPDF 5.7

    return $html;
}