TCPDF 事务:空字体系列

TCPDF Transaction: Empty font family

我正在使用 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);
    }
}

当我不回滚事务而只是提交它时,一切正常。我不知道为什么会出现此错误。您知道问题出在哪里吗?

您好!

错误在

$this->pdf->rollbackTransaction(false);

'false'这里的意思不是恢复$this->pdf到原来的状态,而是恢复到return原来的状态作为一个TCPDF对象,所以正确的是:

$this->pdf = $this->pdf->rollbackTransaction(false);

$this->pdf->rollbackTransaction(true);

错误 "TCPDF ERROR: Empty font family" 只是 $this->pdf 不再有效的后续错误。