在 pdf 生成的 bt fpdf.php 中向 table 行添加颜色
Adding colours to table rows in a pdf generated bt fpdf.php
我使用 php 中的以下代码生成包含 tables 的 pdf!
我想给 table 行添加颜色!我可以使用什么方法向 table 行添加颜色?
<?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。
我使用 php 中的以下代码生成包含 tables 的 pdf! 我想给 table 行添加颜色!我可以使用什么方法向 table 行添加颜色?
<?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。