繁体   English   中英

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

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

我使用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();


?>

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

//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->SetFillColor。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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