好的,所以我在下面复制了我的编码。 我想在PHP代码中应用pdf格式,我已经成功完成了它的工作但我想给它一个样式我如何在我的pdf上应用样式。 我添加了一个表,但我想要行交替的背景颜色
更新〜!!!!
class PDF extends FPDF
{
function BasicTable($header)
{
//Header
for($i=0;$i<10;$i++)
{
$this->SetTextColor(1);
$this->SetDrawColor(128,11,4);
$this->SetLineWidth(1.3);
$this->SetFont('','');
$this->SetFillColor(224,235,5);
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
//Data
}
}
function FancyTable($header)
{
//Colors, line width and bold font
$this->SetTextColor(255,131,13);
$this->SetDrawColor(18,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(40,35,40,45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
//Color and font restoration
$this->SetFillColor(124,25,255);
$this->SetTextColor(130);
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetTextColor(0,0,102);
$pdf->SetXY( 65 , 25 );
$pdf->Write(0, "Requisition Reports");
$pdf->Line(20 , 32 , 195 , 31);
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 20 , 30 );
$pdf->Write(0, "Request ID");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 45, 30 );
$pdf->Write(0, "FOR :");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 70 , 30 );
$pdf->Write(0, "From :");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 95 , 30 );
$pdf->Write(0, "Date :");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 120, 30 );
$pdf->Write(0, "Item :");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 135, 30 );
$pdf->Write(0, "Description :");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 160, 30 );
$pdf->Write(0, "User");
$pdf->SetTextColor(0,0,10);
$pdf->SetFont('Arial','I',10);
$pdf->SetXY( 175, 30 );
$pdf->Write(0, "Status");
$querya=mysql_query("select * from request order by FIELD(Status,'done','pending');");
$b=35;
$ids=array();
$c=40;
while ($row = mysql_fetch_array($querya)) {
$forname=$row['for'];
$fromname=$row['from'];
$req=$row['request_id'];
$queryb=mysql_query("select name from entities where id=$forname;");
while ($row2 = mysql_fetch_assoc($queryb)) {
$forname=$row2['name'];
}
$queryc=mysql_query("select name from entities where id=$fromname;");
while ($row3 = mysql_fetch_assoc($queryc)) {
$fromname=$row3['name'];
}
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 30 , $b );
$pdf->Cell(0,5,$req,1);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 45, $b );
$pdf->Cell(0,5,$forname);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 70 , $b );
$pdf->Cell(0,5,$fromname);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 95 , $b );
$pdf->Cell(0,5,$row['request_date']);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 120 , $b );
$pdf->Cell(0,5,$row['item_name']);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 135 , $b );
$pdf->Cell(0,5,$row['description']);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 165 , $b );
$pdf->Cell(0,5,$row['user']);
$pdf->SetTextColor(124,12,10);
$pdf->SetXY( 175 , $b );
$pdf->Cell(0,5,$row['status']);
//if($row['status']=="done")
//{
//$id=$row['request_id'];
//$queryd=mysql_query("select * from issue where request_id=$id;");
//while ($row4 = mysql_fetch_assoc($queryd))
//{
//$iss_date=$row4['issue_date'];
//$pdf->SetTextColor(11,11,120);
//$pdf->SetXY( 30, $c );
//$pdf->Write(0, "Issue Date:");
//$pdf->SetXY( 50 , $c );
//$pdf->Write(0, $row4['issue_date']);
//$pdf->SetTextColor(11,11,120);
//$pdf->SetXY( 75, $c );
//$pdf->Write(0, "Description:");
//$pdf->SetXY( 95 , $c );
//$pdf->Write(0, $row4['description']);
//$pdf->SetTextColor(11,11,120);
//$pdf->SetXY( 125, $c );
//$pdf->Write(0, "User:");
//$pdf->SetXY( 140 , $c );
//$pdf->Write(0, $row4['user']);
//}
//$header=array();
//$header=array($row4['issue_date'],$row4['description'],$row4['user']);
//}
$b+=15;
$c+=15;
}
$pdf->Output();
?>