我正在使用FPDF php插件从我的SQL表生成PDF。使用SetCol()
和AcceptPageBreak()
函数将PDF分为三列。
但是,生成PDF时,每个新页面的第一列都没有显示标题。
我尝试在Cell()
函数的else语句上添加AcceptPageBreak()
,但是它一直与第一行重叠。另外,最后一页甚至不显示标题行。
谁能告诉我如何添加每个新页面的第一列的标题行?
我设法在最后两列中设置标题,但由于某些原因,它不适用于第一列。
我的代码是:
function output_pdf($id) {
global $wpdb;
if ( $wpdb->get_var( $wpdb->prepare( 'SELECT * FROM wp_tickets WHERE lottery_id= %d AND used = %d', $id, 1 ) ) ) {
$log = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM wp_tickets WHERE lottery_id=%d AND used = %d', $id, 1 ) );
global $pdf;
$title_line_height = 10;
$content_line_height = 8;
$pdf->AddPage('L');
$pdf->SetFont( 'Arial', '', 42 );
$header = array('Order Number', 'Full name (Billing)', 'Draw #');
$pdf->SetFont( 'Arial', 'B', 8);
$pdf->Cell(20,5,'Order Number', 1);
$pdf->Cell(35,5, 'Full name (billing)', 1);
$pdf->Cell(25,5, 'Draw #' ,1);
$pdf->Ln();
$i = 0;
foreach( $log as $row ) {
if($i%2 == 0) :
$pdf->setFillColor(255,255,255);
else :
$pdf->setFillColor(230,230,230);
endif;
$pdf->SetFont( 'Arial', '', 8 );
$pdf->Cell(20,5,$row->order_id, 1, 0, 'C', true);
$pdf->Cell(35,5, $row->first_name .' '. $row->last_name,1, 0, 'C', true);
$pdf->Cell(25,5,$row->ticket_number,1, 0, 'C', true);
$pdf->Ln();
$i++;
}
}
$pdf->Output('D','atomic_smash_fpdf_tutorial.pdf');
exit;
}
var $col = 0;
function SetCol($col)
{
// Move position to a column
$this->col = $col;
$x = 10+$col*98;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
if($this->col<3)
{
// Go to next column
$this->SetCol($this->col+1);
$this->SetY(10);
$this->SetFont( 'Arial', 'B', 8);
$this->Cell(20,5,'Order Number', 1);
$this->Cell(35,5, 'Full name (billing)', 1);
$this->Cell(25,5, 'Draw #' ,1);
$this->SetFont( 'Arial', '', 8 );
$this->Ln();
return false;
}
else
{
// Go back to first column and issue page break
$this->SetCol(0);
$this->SetY(10);
$this->SetFont( 'Arial', 'B', 8);
$this->Cell(20,5,'Order Number', 1);
$this->Cell(35,5, 'Full name (billing)', 1);
$this->Cell(25,5, 'Draw #' ,1);
$this->SetFont( 'Arial', '', 8 );
$this->Ln();
return true;
}
}