首页 > 解决方案 > Arial 粗体的 tFPDF unicode 字符

问题描述

我正在尝试通过 FPDF (tFPDF) 创建 PDF,但我仍然无法使用正确的字符集创建输出。

问题在于捷克字母:ě,š,č,ř,ž,ů 等...

资源:

<?php
require_once('../tfpdf/tfpdf.php');

define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");

$pdf = new tFPDF('P','mm','A5');

$pdf->SetMargins(8,5,8);
$pdf->AddPage();

// Pracoviště
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:','L',0);

$pdf->Output();
?>

我需要写“Pracoviště:”,但输出是“PracoviÅ¡tÄ›:”。

对于常规的 Arial,我通过以下方式解决了它:

$pdf->AddFont('Arial','','arial.ttf',true);

但它不适用于粗体。

我试过了:

$pdf->AddFont('Arial','','arial.ttf',true); // Arial
$pdf->AddFont('Arial','B','arialbd.ttf',true); // Arial Bold

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště:
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: PracoviÅ¡tÄ›:

有趣的是,如果我使用 Arial Black 文件,它可以工作,但它不是我需要的字体。

$pdf->AddFont('Arial','','arial.ttf',true); // Arial
$pdf->AddFont('Arial','B','ariblk.ttf',true); // Arial Black

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště:
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště: - but Arial Black font, I need Arial Bold

为什么 Arial 有效,Arial Black 也有效,而 Arial Bold 无效?如何解决?

标签: unicodeutf-8fpdfbold

解决方案


推荐阅读