我有很多用于创建pdf(TCPDF)的代码,按页眉,正文,页脚分别...
我需要根据需要使用可变坐标调用代码。因为我需要使用if else
调用,所以(当然)有多个调用,因此我不必重写相同的代码。
例如,我尝试使用此(子标题):
class invoice {
function getSubheader($disY){
$subheader = array(
$pdf->SetLineWidth(.2),
$pdf->MultiCell(190,9,'',1,'L',false,0,10,$disY,true),
$pdf->SetFont('freesans','',7),
$pdf->MultiCell(50,"",$getDesc['blabla1'],0,'L',false,0,12,$disY+2,true),
$pdf->MultiCell(15,"",$getDesc['blabla2'],0,'R',false,0,62,$disY+2,true),
$pdf->MultiCell(20,"",$getDesc['blabla3'],0,'R',false,0,77,$disY+2,true),
$pdf->MultiCell(15,"",$getDesc['blabla4'],0,'R',false,0,97,$disY+2,true),
$pdf->MultiCell(25,"",$getDesc['blabla5'],0,'R',false,0,112,$disY+2,true),
$pdf->MultiCell(15,"",$getDesc['blabla6'],0,'R',false,0,137,$disY+2,true),
$pdf->MultiCell(20,"",$getDesc['blabla7'],0,'R',false,0,152,$disY+2,true),
$pdf->MultiCell(25,"",$getDesc['blabla8'],0,'R',false,0,172,$disY+2,true),
$pdf->SetFont('freesans','B',8),
$pdf->MultiCell(180,"",$getDesc['blabla9'],0,'L',false,0,12,$disY+11,true)
);
return $subheader;
}
others functions...
}
在另一个class
中,仅呼叫function
$pdf = new TCPDF (PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
lot of code $pdf->...
$invoice = new invoice();
if(cond == 1){
$disY = 100;
$invoice->getSubheader($disY);
} else {
$disY = 200;
$invoice->getSubheader($disY);
}
lot of code $pdf->...
此function
必须返回变量$ pdf-> SetLineWidt ...等。
但是,如果我使用此解决方案-错误
Call to a member function SetLineWidth() on null
对新手有何建议?