【问题标题】:TCPDF Transaction: Empty font familyTCPDF 事务:空字体系列
【发布时间】:2023-09-30 12:22:01
【问题描述】:

我正在使用 TCPDF 生成 PDF,当我使用事务时出现以下错误: TCPDF 错误:空字体系列

我有以下代码 sn-p(带有分页事务):

            $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);
    }
}

当我不回滚事务而只提交它时,一切正常。我不知道为什么会发生此错误。你知道可能是什么问题吗?

你好!

【问题讨论】:

    标签: php transactions tcpdf fpdf


    【解决方案1】:

    错误在于

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

    'false' 在这里表示不将 $this->pdf 恢复到其原始状态,而是将原始状态 return 作为一个 TCPDF 对象,因此正确的是:

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

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

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

    【讨论】: