C
C
Crash2016-09-30 11:51:33
Yii
Crash, 2016-09-30 11:51:33

How to force mpdf in Yii2 to display Russian letters?

I use this extension: www.yiiframework.com/extension/yii2-mpdf Installed
, configured and everything seems to be fine, but stubbornly refuses to display Russian letters.
The code:

public function actionTest()
    {
        Yii::$app->response->format = Response::FORMAT_RAW;
        $headers = Yii::$app->response->headers;
        $headers->add('Content-Type', 'application/pdf');

        $content = $this->renderPartial('pdf');

        $pdf = new Pdf([
            'mode' => Pdf::MODE_CORE, // leaner size using standard fonts
            // A4 paper format
            'format' => Pdf::FORMAT_A4,
            // portrait orientation
            'orientation' => Pdf::ORIENT_PORTRAIT,
            // stream to browser inline
            'destination' => Pdf::DEST_BROWSER,
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            'content' => $content,
            'options' => [
                'title' => 'Распечатка события - Service Desk',
                'subject' => 'Service Desk'
            ],
            'defaultFont' => 'Arial',
            'methods' => [
                'SetHeader' => ['Service Desk||Generated On: ' . date("Y-m-d H:i:s")],
                'SetFooter' => ['{PAGENO}']
            ]
        ]);

        return $pdf->render();
    }

View:
<p>Документ pdf</p>
Output:
2b42f2145578448089d09ab4e32d4526.jpg
PS:
I changed the display mode to MODE_UTF8, MODE_BLANK and an empty string - all to no avail (in this case it does not render pdf at all, referring to errors in the console)
In php.ini is php_value mbstring.func_overload = 0 - also Does not help

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Fedorov, 2017-06-27
@Pagliaccio

You need
to replace the line with
'mode' => Pdf::MODE_UTF8,

D
Dmitry, 2016-09-30
@slo_nik

Good morning.
So maybe the problem is not in mpdf?
Check if you have the required encoding everywhere (file, server, etc.)

C
coderisimo, 2019-03-02
@coderisimo

$pdf->charset_in = 'utf-8'; ?
and in constructor

$mpdf = new \Mpdf\Mpdf([
        'mode' => 'utf-8',  // вот енто
        'format' => [190, 236], 
        'orientation' => 'L'
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question