简体   繁体   中英

Adding colours to table rows in a pdf generated bt fpdf.php

The following code in php is used by me to generate a pdf which contains tables! I want to add colours to the table rows! What is the method that I can use to add colours to the table rows?

<?php
require("../../db/db.php"); //provides database connection

require("fpdf/fpdf.php");


class PDF extends FPDF{
function Header(){

$this->setFont('Arial','B',14);
$this->Image("logo.png");    

$this->ln(20);
}



}

$sql="SELECT count(Email) as Number, Date from reportorder";
$result=mysqli_query($db,$sql);
$pdf=new PDF();
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','B',12);

$pdf->Cell(90,10,'Date',1,0,'C',0);
$pdf->Cell(90,10,'Number of orders',1,1,'C',0);


while($row=mysqli_fetch_array($result))
{

  // cell with left and right borders

$pdf->Cell(90,10,$row['Date'],1,0,'C',0); // 1,0 
$pdf->Cell(90,10,$row['Number'] ,1,1,'C',0);


}

$pdf->output();


?>

First you'll need to set your fill color:

//RGB colors 0-255, param order is r,g,b you can google RGB colors
//change 100,100,100 to be whatever color you want
$pdf->SetFillColor(100,100,100);

Now flip on the boolean in your Cell to use the fill:

//parameter list for reference
$pdf->Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])

//sample of the heading with use fill boolean fliped (the 1 after the 'C')
$pdf->Cell(90,10,'Date',1,0,'C',true);
$pdf->Cell(90,10,'Number of orders',1,1,'C',true);

To change colors, just run $pdf->SetFillColor again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM