phphtmlmpdfcheckmark

mPDF (PHP) does not recognize html check mark


I am showing a table in HTML on my web page where a check mark is shown properly (I am using ✔ for the bold check mark).

I am using classic-asp to display the HTML. The html buildup (tableOutput) is then posted to a PHP script ($output = $_POST["output"]) that uses mPDF.php (version 6.0) to print to PDF the same HTML table and somehow the check mark wont print correctly (%u2714 in printed on my PDF). All the rest of the table is printed correctly, only the check mark has a problem.

I tried adding the Symbola.ttf and Symbola_hint.ttf fonts in the mpdf\ttfonts folder but it didnt do the trick.

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 (I addded symbola.ttf and Symbola_hint.ttf in the mpdf\ttfonts folder):

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

CSS (PHP $style variable points to 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; }

Thank you very much for your help


Solution

  • There are two possible solutions:

    $output = str_replace('%u2714', '&#10004;', $output);
    
    $output = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $output);
    $output = html_entity_decode($output, ENT_COMPAT, 'UTF-8');