【发布时间】:2020-08-25 04:06:14
【问题描述】:
我正在为我的 laravel 项目使用 fpdf 库。我为页眉和页脚函数创建了一个类。然后在我的 pdf 控制器上调用 thess 函数。我遇到此错误“FPDF 错误:尚未添加页面”,我不知道此错误来自何处。你能教我如何修复这个错误/错误。提前致谢。
来自我的控制器的代码
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Codedge\Fpdf\Fpdf\Fpdf;
use App\Personnel;
use App\Classes\PDFClass;
class PFTReportController extends Controller
{
public function postPFTReport(Request $request)
{
$pdf = new FPDF();
$pdf->AddPage('P', 'A4');
$pdf->Ln(4);
$pdf->SetFont('Arial', '', 12);
// Call the header for this report
$pdfClass = new PDFClass();
$header = $pdfClass->Header();
$pdf->Cell(0, 4, 'Sample Report', 0, 1, 'C');
$pdf->Ln(2);
$pdf->Output();
exit;
}
}
类的代码
namespace App\Classes;
use Codedge\Fpdf\Fpdf\Fpdf;
class PDFClass extends Fpdf
{
protected $B = 0;
protected $I = 0;
protected $U = 0;
protected $HREF = '';
// Page header
function Header()
{
$this->SetFont('Arial', '', 11);
$this->Cell(0, 2, 'Line 1', 0, 1, 'C');
$this->Cell(0, 8, 'Line 2', 0, 1, 'C');
$this->SetFont('Arial', 'B', 12);
$this->Cell(0, 1, 'Line 3', 0, 1, 'C');
$this->Cell(0, 8, 'Line 4', 0, 1, 'C');
$this->SetFont('Arial', '', 12);
$this->Cell(0, 1, 'Line 5', 0, 1, 'C');
$this->Ln(8);
}
}
【问题讨论】: