MPDF - how to set document's default language?

114 Views Asked by At

MPDF should support this according to the logs: Set /Lang entry for better accessibility when document language is available (@cuongmits, Set the default language using /Lang entry #1418)

When adding html lang attribute , MPDF is not picking up on this and setting it accordingly.

More info on default lang: https://www.w3.org/WAI/WCAG22/Techniques/pdf/PDF16

I tried code below but language is still not set:

$html = '<!DOCTYPE html><html lang="en-CA"><head><title>'.$doc_title.'</title><style>body{font-size: 12px;}h1{font-size: 14px}.red-asterisk{color:#cf1818;margin-left:4px;}.underline{border-bottom:2px solid;}.list-no-style{list-style:none;}ul{padding-top:30px;}ul ul{padding-top:0;}li{padding-top:10px;}</style></head><body>' . $prepared_checklist_html . '</body></html>';

$mpdf = new \Mpdf\Mpdf(
    array(
        /*
        'default_font' => 'arial', */
        'default_font_size' => 12,
        'currentLang' => 'en-CA',
        'default_lang' => 'en-CA',
        'tempDir'           => $new_child_directory,
    )
)

$mpdf->curlTimeout  = 10;
$mpdf->simpleTables = true;
$mpdf->SetCompression( true );
$mpdf->PDFA = true;
$mpdf->PDFAauto = true;
$mpdf->SetDisplayMode( 'fullwidth' );
$mpdf->SetTitle( 'Plan Checklist' );
$mpdf->SetDisplayPreferences('DisplayDocTitle');
1

There are 1 best solutions below

0
FED On

Thank you KIKO!

While I did not use 'autoScriptToLang to true' your suggestion of following the trail led me to this link specifically example2 where I found

//Define a new \Mpdf\Mpdf document using win-1252 fonts based on a language/country code
$mpdf = new \Mpdf\Mpdf(['mode' => 'en-GB']);

https://mpdf.github.io/reference/mpdf-functions/construct.html#example-2

So I added the line to my existing instance of MPDF and the PDF document language is now set correctly.

$mpdf = new \Mpdf\Mpdf(
        array(
            'default_font_size' => 12,
            'mode' => 'en-CA',
            'tempDir' => $new_child_directory,
        )
    );