0
我正在尝试编写一个可以调用多个类的函数,每个函数都会将一个小部件添加到单个PDF文件,然后返回整个PDF文件。在多个类中使用TCPDF
这里的构造函数的代码:
<?php
class PdfConstructor {
protected $logger; // I'm sure there's another way to use the logger located in the public dependencies without having to initalise it here
public function __construct($logger){
$this->logger = $logger;
}
public function studentPdf(){
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// ---------------------------------------------------------
require 'pdfwidgets/studentheader.php'; // TODO: Need to load this via autoloader
$headerController = new StudentHeader($pdf);
$headerInfo = $hederController->getHeader();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('C:\xampp7\htdocs\edquire-api\logs\test.pdf', 'F');
}
}
在
studentheader
然后,我有这样的:
<?php
class StudentHeader {
protected $pdf;
public function __construct($pdf){
$this->$pdf = $pdf;
}
public function getHeader(){
$this->pdf->AddPage();
}
}
我想给$pdf
对象传递给studentheader
但我得到的错误:
Catchable fatal error: Object of class TCPDF could not be converted to string in C:\xampp7\htdocs\edquire-api\classes\pdfwidgets\studentheader.php on line 8
它为什么试图将其转换为字符串,并有没有更好的方法来实现使用小部件构建PDF?
投票关闭,因为你只是要求我们找到你的错字。 –