php 单元格内的背景颜色在 fpdf 中没有改变
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27894890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Background Color inside a cell is not changing in fpdf
提问by Larcy
Im using fpdf to generate a pdf file for my reports and Im new to this. I want to change the fill color inside a cell but whenever I reloaded the page, nothing hapeens, It still the same white fill color. Here is my code :
我使用 fpdf 为我的报告生成一个 pdf 文件,而我对此并不陌生。我想更改单元格内的填充颜色,但是每当我重新加载页面时,什么都没有发生,它仍然是相同的白色填充颜色。这是我的代码:
<?php
require("fpdf/fpdf.php");
$pdf = new FPDF('P','pt','Letter');
$pdf->SetFillColor(230,230,230);
$pdf->SetTitle("Title Here");
$pdf -> AddPage();
$pdf -> SetFont('Arial','',12);
?>
What is wrong with my code? I followed the proper way of setting the fill color but nothing happens? Can anyone help me fix it? Thanks
我的代码有什么问题?我遵循了设置填充颜色的正确方法,但没有任何反应?任何人都可以帮我修复它吗?谢谢
回答by JuanSedano
Tyr something like:
提尔类似:
$pdf->setFillColor(230,230,230);
$pdf->Cell(0,10,$text,0,1,'L',1); //your cell
Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
定义用于所有填充操作(填充矩形和单元格背景)的颜色。它可以用 RGB 分量或灰度表示。可以在创建第一个页面之前调用该方法,并将值从页面保留到页面。
Take a look to the FPDF manual
看一看FPDF 手册
回答by M.Z.Assafly
mpdf->SetFillColor('RED');
Just set the seventh parameter equal to TRUE
只需将第七个参数设置为 TRUE
$mpdf->WriteCell(38, 10, 'HELLO', 1, 0, 'C', TRUE);