簡體   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