使用php创建带有表情符号utf-8字符的PDF

使用php创建带有表情符号utf-8字符的PDF,php,codeigniter,tcpdf,mpdf,utf8mb4,Php,Codeigniter,Tcpdf,Mpdf,Utf8mb4,我正在尝试创建包含表情符号的文本的pdf 使用PHP>7和mysql “字符集”=>utf8mb4 'dbcollat'=>utf8mb4\u unicode\u ci 我已经从html创建PDF,是回显html文本所有表情显示良好。但是如果它创建pdf,它就不能转换 请帮忙解决这个问题 例如:“One\ud83d\ude02” 谢谢 这里有更多的解释来简化我的问题 $fileName = $source_path.'example.pdf'; //using php codeignitor

我正在尝试创建包含表情符号的文本的pdf

使用PHP>7和mysql

“字符集”=>utf8mb4

'dbcollat'=>utf8mb4\u unicode\u ci

我已经从html创建PDF,是回显html文本所有表情显示良好。但是如果它创建pdf,它就不能转换

请帮忙解决这个问题

例如:“One\ud83d\ude02”

谢谢

这里有更多的解释来简化我的问题

$fileName = $source_path.'example.pdf';

//using php codeignitor 3.1.2

$htmlContent = $this->load->view('view/view_pdf', $data, TRUE); 
$htmlContent = <<<EOD
 $htmlContent 
EOD;

// call pdf create function 
$this->createPDF($fileName, $htmlContent);

// these character working correct as echo output on browser and send in email subject n body.
 echo decodeEmoticons("One \ud83d\ude02"); 
 echo "One \u{1F602}"; 

/*******************************/ 
// helper functions
function checkJson($title){
    if (json_decode($title, true) !== null) {
        $title =  str_replace('"', '', json_decode($title));
    }else{
         $title = str_replace('"', '', $title);
    }
    return $title;
 }

 function decodeEmoticons($src) {
    $replaced = preg_replace("/\\\\u([0-9A-F]{1,4})/i", "&#x$1;", $src);
    $result = mb_convert_encoding($replaced, "UTF-16", "HTML-ENTITIES");
    $result = mb_convert_encoding($result, 'utf-8', 'utf-16');
    $result = checkJson($result);
    return $result;
} 

/*******************************/ 

pdf输出显示的表情符号不正确。

您是如何创建pdf的?请尝试解释您迄今为止尝试的内容,可能会显示pfd文件和您使用的代码。这将使您更容易使用JavaScript
\u####
转义序列在PHP中没有任何意义。(.)你是说
“One\u{d83d}\u{de02}”
是偶然的吗?我猜
dejavusans
没有表情符号。浏览器会使用回退字体动态替换丢失的图示符。TCPDF可能没有。是否有其他解决方案来完成此任务?我准备更改TCPDF以外的库。但我想很快提供这个功能。
<div class="row">   
    <div class="col-lg-12">

    <table class="table dataTable" border="0" cellpadding="0" cellspacing="0" width="100%">
        <tbody>

            <tr>
                <td colspan="3"> </td>
            </tr>
            <tr>
                <td width="60%"><b>Event Name:</b> <?php echo decodeEmoticons("One \ud83d\ude02"); ?> </td>
                <td width="60%"><b>Event Name:</b> <?php echo "One \u{1F602}"; ?> </td>
                <td><b>Start Time:</b> <?php echo date('F j, Y, g:i A', time()); ?></td>
            </tr>

            <tr>
              <td colspan="3"></td>
            </tr>
        </tbody>
    </table>
    </div>
</div>
public function createPDF($fileName, $htmlContent) {
        /*
        http://www.tcpdf.org
// File name   : tcpdf.php
// Version     : 6.2.13
// Begin       : 2002-08-03
// Last Update : 2015-06-18
       */
    ob_start(); 
    // Include the main TCPDF library (search for installation path).
    $this->load->library(array('Tcpdf'));

    // create new PDF document
    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    //$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);

    // set document information 
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('auth');

    $pdf->SetTitle('Event ');
    $pdf->SetSubject('Event ');
    $pdf->SetKeywords('Event ');

    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

    // set header and footer fonts
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);

    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(10);
    $pdf->SetFooterMargin(30);

    // set auto page breaks
    //$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->SetAutoPageBreak(TRUE, 30);

    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

    // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
        require_once(dirname(__FILE__).'/lang/eng.php');
        $pdf->setLanguageArray($l);
    }       


    $pdf->SetFont('dejavusans', '', 10);

    //$pdf->SetFont('halvatica', '', 10); // this is also trying but fail

    // add a page
    $pdf->AddPage();    

    //$htmlContent = utf8_encode($htmlContent);// this is also trying but fail

    // output the HTML content
    $pdf->writeHTML($htmlContent, true, false, true, false, '');

    // reset pointer to the last pagend output PDF document
    $pdf->lastPage();  

    ob_end_clean();
    //Close and output PDF document
    $pdf->Output($fileName, 'F');        
}