在pdf生成的bt fpdf.php中为表行添加颜色

时间:2017-01-13 16:23:01

标签: php pdf colors fpdf

我使用php中的以下代码生成包含表格的pdf! 我想为表格行添加颜色!我可以用什么方法为表行添加颜色?

<?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();


?>

1 个答案:

答案 0 :(得分:0)

首先,您需要设置填充颜色:

//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);

现在翻转单元格中的布尔值以使用填充:

//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);

要更改颜色,只需再次运行$ pdf-&gt; SetFillColor。