动态fpdf表创建仅在第一页有效
我第一次使用fpdf,我已经创建了一个函数,可以动态生成pdf格式的表格,并根据单元格中的文本调整表格行的高度。它在第一页上很有魅力,但在所有其他页面上看起来都很奇怪,到处都是游离的单元格和文本。如何将文件附加到此页 我的代码如下:动态fpdf表创建仅在第一页有效,pdf,fpdf,Pdf,Fpdf,我第一次使用fpdf,我已经创建了一个函数,可以动态生成pdf格式的表格,并根据单元格中的文本调整表格行的高度。它在第一页上很有魅力,但在所有其他页面上看起来都很奇怪,到处都是游离的单元格和文本。如何将文件附加到此页 我的代码如下: $pdf=new PDF(); $pdf->AddPage('P', '', 'A4'); $pdf->SetLineWidth(0,2); $pdf->SetFont('Arial','B',14); $pdf->Cell(75,25,$p
$pdf=new PDF();
$pdf->AddPage('P', '', 'A4');
$pdf->SetLineWidth(0,2);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(75,25,$pdf->Image($imgurl, $pdf->GetX(100), $pdf->GetY(), 40),0,0);
$pdf->Cell(250,25,$kw[555],0,1);
//this is the function that makes the table
$pdf->CreateDynamicTable($array,$finalData);
$pdf->Output();
class PDF extends FPDF{
public $padding = 10;
function CreateDynamicTable($array,$data){
$this->SetFillColor(191, 191, 191);
$this->SetFont('Arial', 'B', 9);
foreach($array AS $name => $confs){
$this->Cell($confs['width'],10,$confs['header'],1,0,'C', true);
}
$this->Ln();
$x0=$x = $this->GetX();
$y = $this->GetY();
foreach($data as $rows=>$key){
$yH = $this->getTableRowHeight($key,$array);
foreach($array AS $name => $confs){
if(isset($key[$name])){
$this->SetXY($x, $y);
$this->Cell($confs['width'], $yH, "", 'LRB',0,'',false);
$this->SetXY($x, $y);
$this->MultiCell($confs['width'],6,$key[$name],0,'C');
$x =$x+$confs['width'];
}
}
$y=$y+$yH; //move to next row
$x=$x0; //start from first column
}
}
public function getTableRowHeight($key,$array){
$yH=5; //height of the row
$temp = array();
foreach($array AS $name => $confs){
if(isset($key[$name])){
$str_w = $this->GetStringWidth($key[$name]);
$temp[] = (int) $str_w / $confs['width'];
}
}
$m_str_w = max($temp);
if($m_str_w > 1){
$yH *= $m_str_w;
}
$yH += $this->padding;
return $yH;
}
}
我认为这是因为使用了蜂窝和多蜂窝。有时,您会有一个单元格,其高度将超过页面,AutoPageBreak会将该数据扔到下一页
尝试$pdf->SetAutoPageBreak false;当您知道自己位于页面底部时,请使用AddPage。要获得正确的单元格高度,您需要先获得行中所有单元格的最大高度,然后决定是在当前页面还是下一页进行输出。这就是我最后要做的,它工作得非常好。基本上,它现在只在$y>270时添加一个页面,并使用剩余的$data再次调用相同的函数