php - FPDF:在单元格内更改文本颜色?

标签 php text colors cell fpdf

我想要它,这样说白色的文本将使用 SetTextColor 作为白色,而橙色使用橙色。

$pdf->SetTextColor(255,255,255);
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C');

如何影响“ORANGE”字词使用橙色文本颜色?

最佳答案

可以通过一些小技巧来实现。我只是让它打印 2 个单元格,一个叠在另一个单元格上,如下所示:

//Setting the text color to black
$pdf->SetTextColor(0,0,0);

//Printing my cell      
$pdf->SetFont('Arial','B');
$pdf->Cell(55,5,"Black Text ",1,0,'C');
$pdf->SetXY($coordXbase,$coordY);

//Setting the text color to red
$pdf->SetTextColor(194,8,8);

//Printing another cell, over the other
$pdf->SetFont('Arial','B');
//Give some space from the left border, and print the red text after the black text that is in the cell behind this one.
$pdf->Cell(55,5,"                        Red Text",0,0,'C');
$pdf->SetXY($coordXbase,$coordY);

//Setting the text color back to back, in the next cells.
$pdf->SetTextColor(0,0,0);

结果是这样的:

Multicollor cell result

因为我有点匆忙,我没有时间创建一些函数来帮助解决这个问题,但这将是一个很好的起点 :)

P.S.:告诉你们是否找到更简单的方法。

关于php - FPDF:在单元格内更改文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328848/

相关文章:

php - LDAP 过滤器 : getting only users updated since given date

php - Ajax 登录和 javascript cookie,这安全吗?

javascript - 我可以将日程安排作为 ajax 放在 fullcalendar 中吗?

shell - 合并多个文本文件并删除重复项

vim - 在 Vim 中将光标移过长的软环绕行

c# - 如何从pdf中获取pantone色号?

c - 在 640x480 16 色 VGA 模式下绘制像素时出现问题

php - 按特定顺序的 URL 旋转器

python - 在 python 中将图像转换为字符串后存档图像

使用绑定(bind)的 WPF DataGrid 单元格背景