mPDF(PHP)无法识别HTML勾选标记

3

我在我的网页上展示了一个HTML表格,在其中正确显示了一个勾选标记(我使用✔来表示粗体勾选标记)。

我使用classic-asp来显示HTML。然后将html组成(tableOutput)发布到一个PHP脚本($output = $_POST["output"]),该脚本使用mPDF.php(版本6.0)打印相同的HTML表格,但是勾选标记无法正确打印(在我的PDF上输出%u2714)。所有其余表格都正确打印,只有勾选标记有问题。

我尝试将Symbola.ttf和Symbola_hint.ttf字体添加到mpdf\ttfonts文件夹中,但这并没有起作用。

HTML(classic-asp)

tableOutput = tableOutput & "<TD class='center pass_x' style='font-family:symbola;'>&#10004;</TD>"

PHP(create_report_pdf.php):

$output = $_POST["output"];  //This is the html buildup tableOutput discussed previously
$header = Irrelevant;
$footer= Irrelevant;

$mpdf = new mPDF( 'utf-8', 'A4-L', 0, '', 5, 5, 20, 20);
$mpdf->allow_charset_conversion = true;
$mpdf->WriteHTML($style,1);
$mpdf->SetHTMLHeader( $header );
$mpdf->SetHTMLFooter( $footer );
$mpdf->WriteHTML( $output );
$mpdf->Output($temp ,'F' );

config_fonts.php(我将symbola.ttf和Symbola_hint.ttf添加到mpdf\ttfonts文件夹中):

$this->fontdata = array (
        "symbola"  => array (
                'R' => "Symbola.ttf",
                'I' => "Symbola_hint.ttf",
        ),

CSS(PHP $style变量指向create_report_pdf.css)

.report-table{ 
    border: 1px solid black;
    border-collapse: collapse;
    font-size: 7pt; 
    width: 100%;
} 

th,td{ 
    font-size: 7pt; 
    border: 1px solid black !important;
    vertical-align : middle;
}

.center{ text-align: center; vertical-align: middle; }

INPUT{
    border-color:#ffffff !important;
}

.pf{ width: 45px; }
.fix-cell{ width: 90px; }
.dr-column, .dr-input{ width: 100px; }
.comments, .comments-input{ width: 130px; }


非常感谢您的帮助。
1个回答

2

这里有两种可能的解决方案:

  • 手动替换%u2714为对应的html实体&#10004;,具体操作如下:
$output = str_replace('%u2714', '&#10004;', $output);
  • 实现更通用的方法来处理所有这些特殊字符。该方法基于一个事实,即%uXXXX是URL编码Unicode字符的非标准符号方案。因此,您需要将%uXXXX记法转换为HTML实体记法&#xXXXX;,然后可以通过html_entity_decode将其解码为实际的UTF-8。
$output = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $output);
$output = html_entity_decode($output, ENT_COMPAT, 'UTF-8');

我使用了您的第一个建议($output = str_replace('%u2714', '✔', $output); ),它完美地解决了问题。非常感谢您。 - Christian Caron
@ChristianCaron 很高兴听到我能帮到你,那么你可以接受/点赞我的答案吗? - Plamen Nikolov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接