phpwkhtmltopdf: Problems for printing UTF-8 characters on footer/ header

I am now generating PDF with Chinese characters on both its header and footer:

$title = '中文字';

$options = array(       
        'encoding' => 'UTF-8',  // option with argument
        'header-left' => $title,        
        'footer-html' => 'footer.html',     
        'replace' => array(
            'title' =>$title
        ),
    );

Currently, the header can print out the characters fine, but for the footer, that I include an external html file for it and pass it through replace, the characters printed out becomes unrecognizable.

I already have <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8" http-equiv="encoding"> inside the head tag of my footer.html file. How can I solve this? Thank you very much.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@newpen Can you try adding this line somewhere on top of your script:

setlocale(LC_CTYPE, "en_US.UTF-8");

I could reproduce the issue and this fixed it. I will try to include this in https://github.com/mikehaertl/php-shellcommand.

Had no time to reproduce yet. But this is rather a problem of https://github.com/mikehaertl/php-shellcommand.

I’ve opened the above issue there. What could work: pass a LANG environment variable to proc_open:

$pdf = new Pdf([
    'commandOptions' => [
        'procEnv' => [
            'LANG' => 'en_US.utf-8',
        ],
    ],
]);