mpdf-html转PDF,中文字符乱码、加粗问题

$defaultConfig = (new ConfigVariables())->getDefaults();
                $fontDirs = $defaultConfig['fontDir'];
                $defaultFontConfig = (new FontVariables())->getDefaults();
                $fontData = $defaultFontConfig['fontdata'];
                $mArr = [
                'tempDir'=>__DIR__.'/tmp',
                'fontDir' => array_merge($fontDirs, [ resource_path(). '/fonts', ]),
                    'fontdata' => $fontData + [
                        'simsun' => [
                            'R' => 'simsun.ttf',
                            'B' => "simsun-bold.ttf",
                            ]
                        ], 'default_font' => 'simsun'
                ];

                //生成pdf
                $mpdf = new Mpdf($mArr);
         $mpdf->SetDisplayMode('fullpage');
         $mpdf->ignore_invalid_utf8 = true;
          $mpdf->text_input_as_HTML = true;
         $mpdf->useAdobeCJK = true;
         $mpdf->autoScriptToLang = true;
         $mpdf->autoLangToFont = true;
         $mpdf->showWatermarkText = true;
         $mpdf->WriteHTML($html);
         $mpdf->Output();

 

 ps:resource_path()新增字体路径

R:字体;B加粗;I:斜体;BI加粗斜体;

参考:https://blog.csdn.net/alexandsunny/article/details/81457896?utm_source=blogxgwz7

posted @ 2018-12-21 16:22  pengcx  阅读(1235)  评论(0编辑  收藏  举报