使用 FPDF & FPDI & TCPDF

Using FPDF & FPDI & TCPDF

我想在 PDF 模板上写一些文本,我使用以下方法实现了这一点: FPDF 和 FPDI 库。

我的代码:

<?PHP

include_once('fpdf.php');
require_once('fpdi.php');

$dbhost="xxx";
$dbuser="xxx";
$con = mysqli_connect($dbhost,$dbuser, "");
if (!$con) 
    {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
mysqli_select_db($con,'ecertificate');

$id = $_GET['id'];

$result = mysqli_query($con,"SELECT `eventinfo`.`Date`,`eventinfo`.`template`,`eventinfo`.`cer_title`, `attendeesinfo`.`fullName`,
`attendeesinfo`.`email`,`attendeesinfo`.`eventID`

FROM `attendeesinfo` INNER JOIN `eventinfo` ON 
`attendeesinfo`.`eventID`=`eventinfo`.`ID` WHERE `attendeesinfo`.ID='$id'");
if (mysqli_num_rows($result) > 0)
    {
        while($row = mysqli_fetch_assoc($result)) 
            {
                $cer_title =$row['cer_title'];
                $date =$row['Date'];
                $template =$row['template'];
                $fullName =$row['fullName'];
                $email =$row['email'];
                $event_ID = $row['eventID'];
            }
$newDate = date("d-m-Y", strtotime($date));

$pdf =& new FPDI();
$pdf->addPage('L');
$pagecount = $pdf->setSourceFile('template/'.$template);
$tplIdx = $pdf->importPage(1); 
$pdf->useTemplate($tplIdx); 
$pdf->SetFont('Times','IB',30);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(0,62);
$pdf->Cell(0, $height, $fullName, 0, 0, 'C');
$pdf->SetXY(0, 102); 
$pdf->Cell(0, $height, $cer_title, 0, 0, 'C');
$pdf->SetFont('Times','IB',20);
$pdf->SetXY(0, 140); 
$pdf->Cell(0, $height, $newDate, 0, 0, 'C');
$pdf->Output();
}
?>

问题是

在书写阿拉伯文本(UTF-8 编码)的情况下,文本显示为问号。

我解决这个问题的历程

我发现 TCPDF 支持 UTF-8 Unicode 和从右到左的语言 (https://tcpdf.org/),当我使用它时,我发现不支持某些方法,如 setSourceFile (调用未定义的方法 TCPDF::setSourceFile()) 然后我找到了这个问题的解决方案,它是从 FPDI 和 FPDF 继承 类,但我无法实现,所以我在这里停下来...

帮助我更改我的代码以使用所有库,这样英语和阿拉伯语的大小写就不会成为问题.

在 FPDI 之前只需要 TCPDF 而不是 FPDF。届时 FPDI 将扩展 TCPDF。