我正在尝试使用 FPDF 渲染学士/硕士论文的封面内容。
我需要能够显示捷克字母表,包括带有标点符号的字符(例如 ř、č、ž、ý、ě)。因此,我在 http://fpdf.fruit-lab.de/index.php 上生成了 FPDF 字体文件。来自本地 Times New Roman TTF 字体文件。
我正在使用以下代码来渲染封面。
function toISO($text) {
return iconv('UTF-8', 'ISO-8859-2', $text);
}
function buildImpressionPDF($school, $faculty, $thesisType, $firstname, $surname, $year)
{
$pdf = new FPDF();
$pdf->AddPage();
$pdf->AddFont('times', '', 'times.php');
$pdf->SetFont('times', '', 18);
$pdf->setMargins(0, 0, 0);
$pdf->SetAutoPageBreak(false);
$pdf->Cell(0, 20, toISO($school), 0, 0, 'C');
$pdf->SetY(20);
$pdf->Cell(0, 20, toISO($faculty), 0, 0, 'C');
$pdf->SetY(($pdf->h / 2) - 10);
$pdf->Cell(0, 20, toISO($thesisType), 0, 0, 'C');
$pdf->SetY(-40);
$pdf->Cell(0, 20, toISO($firstname . ' ' . $surname), 0, 0, 'C');
$pdf->SetY(-30);
$pdf->Cell(0, 20, toISO($year), 0, 0, 'C');
return $pdf;
}
文本呈现良好,包括标点符号,但没有正确对齐 - 有些行比其他行更靠右。
我怀疑这可能是自定义字体的问题。当我使用原始的 FPDF 字体时,它似乎很好(但我没有彻底调查),但当然没有正确显示标点符号。
我做错了什么?
最佳答案
请使用 TCPDF 而不是 FPDF 或者试试这个
$pdf->Cell(20,10,'Title',1,1,'C');
关于php - FPDF 无法正确居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16145670/