FPDF 不需要额外生成的页面

FPDF dont want extra generated page

您好,我正在使用 fpdf,这是我的代码:

<?php
   require('fpdf/fpdf.php');

   $pdf = new FPDF('P','mm',array(45,10));
   $pdf->SetMargins(0,5,0);    
   $pdf->AddPage('L');
   $pdf->SetFont('Arial','B',9);
   $pdf->Cell(0, 0,'ASERJFBJGFJSFDS');
   $pdf->Output('label','I');
?>

这会生成一个我不想要的额外页面。第一页空白,第二页完美

FPDF的Cell方法在检测到添加的内容将超出分页边距时触发自动分页(并且AutoPageBreak的值为true,这是默认值)。

只需在添加单元格之前将分页边距设置为较小的值即可。我设法让你的代码通过添加只输出一页:

$pdf->SetAutoPageBreak(true, 5);