如何使用php为pdf中的单元格着色?

如何使用php为pdf中的单元格着色?,php,pdf,Php,Pdf,我需要为从MySQL数据库生成的pdf中的特定单元格指定颜色,如何将颜色设置为特定值 我不知道给特定值加颜色,有什么办法帮我吗 我的pdf生成页面是: $fdate = date('Y-m-d H:i:s', strtotime($fromdate)); $tdate = date('Y-m-d H:i:s', strtotime( $todate)); /*$channelsCol = Channels::find() ->select(['ch

我需要为从MySQL数据库生成的pdf中的特定单元格指定颜色,如何将颜色设置为特定值

我不知道给特定值加颜色,有什么办法帮我吗

我的pdf生成页面是:

$fdate = date('Y-m-d H:i:s', strtotime($fromdate));
$tdate = date('Y-m-d H:i:s', strtotime( $todate));

/*$channelsCol = Channels::find()
                    ->select(['channel_name'])
                    ->where('DeviceRefID != :id',['id' => 0 ])
                    ->orderBy('channel_no')
                    ->all();*/
$channelscol = \Yii::$app->db
                    ->createCommand("select channel_name from channels where deviceRefID !=0")
                    ->queryAll();

$pdfpages = $this->getNoOfPdfs(count($channelscol));
$noOfPages = count($pdfpages[0]);
$collist=[];
$selectlist=[];
for($i=0; $i < $noOfPages;$i++)
{
    $collist[$i] = 'Select SQL_BUFFER_RESULT "LogDateTime  ",';
    $selectlist[$i] = 'select LogDateTime,'; 
}

$count =0;
$counter=1;

for($i=0;$i<$noOfPages;$i++)
{
    for($j=$pdfpages[0][$i];$j<$pdfpages[1][$i];$j++)
    {
        $collist[$i] = $collist[$i] . '"'.$channelscol[$j-1]['channel_name'] .'",';
        $selectlist[$i] = $selectlist[$i] . 'Channel'.$j.'Value,';
        $count = $count + 1;
    }
}

for($i=0;$i <$noOfPages ;$i++)
{
    $collist[$i] = rtrim($collist[$i],",");
    $selectlist[$i] = rtrim($selectlist[$i],",");
}

//$path ="/var/www/devicesadmin/yii-app/web/devicelog/devicelog" . date("Y-m-d-H-i-s").".csv";
$logfilename =[];
$logfailure="";
for($i=0;$i < $noOfPages; $i++)
{   
    $logfilename[$i] = $pdfpages[2][$i] . date("Y-m-d-H-i-s") . mt_rand() . ".csv";
    //$path ='D:/Raffi/ProjectsPhp/DevicesAdminProject/yii-app/web/devicelog//' . $logfilename[$i];
    $path =  "/var/www/devicesadmin/yii-app/web/devicelog/"  . $logfilename[$i];
    $export =' INTO OUTFILE "' . $path . '" FIELDS TERMINATED BY "," ENCLOSED BY \'"\' LINES TERMINATED BY \'\\n\' FOR UPDATE';
    $whereclause = "where LogDatetime between '" . $fdate . "' and '" .$tdate ."'";
    $finalsql = $collist[$i] . ' Union all ' .$selectlist[$i] .' From devicelog '. $whereclause . $export;
    try {
       Yii::$app->db->createCommand($finalsql)->execute();
       //file_put_contents("D:\my.txt", $this->getHTML($path, $header));
       //echo html($this->getHTML($path, $header));
       //exit();        
        $pdf=new \PDF('P','mm','Legal');
        $pdf->AliasNbPages();
        //$pdf=new \PDF('L','mm','Legal',130);
        $pdf->AddPage();
        $pdf->SetFont('helvetica','',10);
        $pdf->WriteHTML($this->getHTML($path));
        $logfilename[$i] = "dl" . $pdfpages[2][$i] . date("Y-m-d-H-i-s").".pdf";
        //$filename = "D:/Raffi/ProjectsPhp/DevicesAdminProject\yii-app\web\devicelog" . $logfilename[$i];
        $filename = "/var/www/devicesadmin/yii-app/web/devicelog/"  . $logfilename[$i];
        $pdf->Output('F',$filename);
        unset($pdf);
    } catch(Exception $e) {

    }
}
如果生成pdf,我需要为大于50的值指定红色。但我无法得到值并给出颜色