我正在使用TCPDF生成PDF,使用事务时出现以下错误: TCPDF错误:空字体系列
我有以下代码段(具有用于分页符的事务):
$titleDesc = $sPDFQuestion;
$pageNum = $this->pdf->PageNo();
$this->pdf->startTransaction();
$this->pdf->Bookmark($sPDFQuestion, 1, 0);
$this->pdf->titleintopdf($pdfTitle, $sPDFQuestion);
if($pageNum != $this->pdf->PageNo()){
$this->pdf->rollbackTransaction(false);
$this->pdf->AddPage('P', 'A4');
$this->pdf->Bookmark($sPDFQuestion, 1, 0);
$this->pdf->titleintopdf($pdfTitle, $sPDFQuestion);
}
else {
$this->pdf->commitTransaction();
}
这是函数titleintopdf():
public function titleintopdf($title, $description = '')
{
if (!empty($title)) {
$title = $this->delete_html($title);
$oldsize = $this->FontSizePt;
$this->SetFontSize($oldsize + 4);
$this->Line(5, $this->y, ($this->w - 5), $this->y);
$this->ln(3);
$this->MultiCell('', '', $title, '', 'C', 0);
$this->MultiCell('', '', "Number:".$this->PageNo(), '', 'C', 0);
if (!empty($description) && isset($description)) {
$description = $this->delete_html($description);
$this->ln(7);
$this->SetFontSize($oldsize + 2);
$this->MultiCell('', '', $description, '', 'C', 0);
$this->ln(2);
} else {
$this->ln(4);
}
$this->MultiCell('', '', "Number:".$this->PageNo(), '', 'C', 0);
$this->Line(5, $this->y, ($this->w - 5), $this->y);
$this->ln(5);
$this->SetFontSize($oldsize);
}
}
当我不回滚事务而只是提交它时,一切正常。我不知道为什么会发生此错误。您知道可能是什么问题吗?
问候!
答案 0 :(得分:0)
错误在于
$this->pdf->rollbackTransaction(false);
'false'表示此处不将$ this-> pdf恢复为原始状态,而是返回作为TCPDF对象的原始状态,因此正确的方法是:
$this->pdf = $this->pdf->rollbackTransaction(false);
或
$this->pdf->rollbackTransaction(true);
错误“ TCPDF错误:空字体家族”只是$ this-> pdf不再有效的后续错误。