首页 文章

在mpdf中显示星星(&#9733)

提问于
浏览
0

我怎么把一些明星★( ★ )放在使用MPDF的pdf中,但它不起作用

这是代码:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='UTF-8';

$html ="";

ob_start();

$obj = json_decode($myJSON,true);
foreach($obj as $data)
{
    if($data['llave'] == 'Autoritario')
    {
        for($i=0;$i<$data['stars'];$i++)
        { 
            echo "&#9733;"; 
        }
    }
}

$html = ob_get_contents();//get the content
ob_end_clean();//erase the output buffer
$mpdf->WriteHTML($html);
$mpdf->Output();
?>

我试过了:

$mpdf->WriteHTML(utf8_encode($html));

和:

{ 
    echo utf8_encode("&#9733";)

但它不起作用,它告诉我:

enter image description here

1 回答

  • 0

    我曾经遇到过同样的问题 . 诀窍是使用支持您要打印的字符的自定义字体更改默认字体 .

    要将自定义字体添加到MPDF,请将century-gothic.tff下载并复制到mpdf文件夹中的ttfonts文件夹 . 下载链接:https://www.wfonts.com/font/century-gothic

    更改MPDF配置中的默认字体 .

    $mpdf = new \Mpdf\Mpdf([
                'mode' => 'utf-8',
                'format' => 'A4',
                'default_font' => 'mycustomfont',
                'margin_left' => 15,
                'margin_right' => 10,
                'margin_top' => 16,
                'margin_bottom' => 10,
                'margin_header' => 10,
                'margin_footer' => 10
        ]);
    

    现在,将您的自定义字体添加到fontVairables.php //mpdf/source/config/fontVariables.php

    "mycustomfont" => [
        'R' => "century-gothic.ttf",
        'B' => "century-gothic-Bold.ttf",                   
     ],
    

相关问题