 |
Downloads > Add-On |
 |
|
 |
| |
|
|
|
|
| |
HTML colors
InformationsAuthor: MorphSoft License: Freeware
DescriptionThis script allows you to use colors using the HTML convention. You can either use the form
#RRGGBB or one of the 16 standard color names.
Source
<?php require('fpdf.php');
class PDF_HTMLColor extends FPDF { function HTML2RGB($c, &$r, &$g, &$b) { static $colors=array('black'=>'#000000', 'silver'=>'#C0C0C0', 'gray'=>'#808080', 'white'=>'#FFFFFF', 'maroon'=>'#800000', 'red'=>'#FF0000', 'purple'=>'#800080', 'fuchsia'=>'#FF00FF', 'green'=>'#008000', 'lime'=>'#00FF00', 'olive'=>'#808000', 'yellow'=>'#FFFF00', 'navy'=>'#000080', 'blue'=>'#0000FF', 'teal'=>'#008080', 'aqua'=>'#00FFFF');
$c=strtolower($c); if(isset($colors[$c])) $c=$colors[$c]; if($c{0}!='#') $this->Error('Incorrect color: '.$c); $r=hexdec(substr($c, 1, 2)); $g=hexdec(substr($c, 3, 2)); $b=hexdec(substr($c, 5, 2)); }
function SetDrawColor($r, $g=-1, $b=-1) { if(is_string($r)) $this->HTML2RGB($r, $r, $g, $b); parent::SetDrawColor($r, $g, $b); }
function SetFillColor($r, $g=-1, $b=-1) { if(is_string($r)) $this->HTML2RGB($r, $r, $g, $b); parent::SetFillColor($r, $g, $b); }
function SetTextColor($r, $g=-1, $b=-1) { if(is_string($r)) $this->HTML2RGB($r, $r, $g, $b); parent::SetTextColor($r, $g, $b); } } ?>
|
Example
<?php define('FPDF_FONTPATH', 'font/'); require('htmlcolor.php');
$pdf = new PDF_HTMLColor(); $pdf->AddPage(); $pdf->SetDrawColor('blue'); $pdf->SetFillColor('#EE7070'); $pdf->SetTextColor('yellow'); $pdf->SetLineWidth(1); $pdf->SetFont('Arial', '', 16); $pdf->SetXY(80, 40); $pdf->Cell(50, 20, 'HTML Colors', 1, 0, 'C', 1); $pdf->Output(); ?>
|
View the result here.
DownloadZIP | TGZ
| |