使用 TCPDF 问题生成带有阿拉伯语和拉丁语单词的 pdf

问题描述

我在使用 tcpdf 库在 pdf 中显示阿拉伯语单词时遇到问题。 我使用了这个 example 但它只有在我使用 $pdf-Cell() 方法时才有效,当我使用 $pdf->writeHTML() 时它显示“???”,我需要使用 writeHTML()。

这是代码

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false,true);
    $template = file_get_contents("file_template.html");

    $pdf->SetMargins(PDF_MARGIN_LEFT,10,PDF_MARGIN_RIGHT);
    $pdf->SetAutopageBreak(TRUE,PDF_MARGIN_BottOM);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(true);
    $lg = Array();
    $lg['a_Meta_charset'] = 'UTF-8';
    $lg['a_Meta_dir'] = 'rtl';
    $lg['a_Meta_language'] = 'ar';
    $lg['w_page'] = 'page';
    $pdf->setLanguageArray($lg);
    $pdf->AddPage();
    $pdf->setRTL(false);
    $pdf->SetFont('aealarabiya','',18);
    $data = str_replace('{' . $key . '}',trim($dictionary["$key"]),$html);
    $template = str_replace("{Data}",$data,$template);
    $pdf->writeHTML($template,0);
    $file = 'file-' . date('dmY-His') . '.pdf';
    return $pdf->Output($file,"D");

PS:数据来自数据库

解决方法

嗯,问题出在 CSS 级别,我对 HTML 文件中的所有标签都使用了 font-family: serif,而阿拉伯语不支持 serif 字体。

当我改变它时,它工作得很好。