gillweb
gillweb

Reputation: 91

How can i pass a conditional variable into a SetTextColor with FPDF?

I have a simple If statement which shows a different RGB color code depending on the result of the "IF". Problem here is if i try and pass that variable to SetTextColor in FPDF it's not read? Any help on how to do this?

$approvalcolor = "34,139,34";
$pdf->SetTextColor($approvalcolor);

Using that type of code the text color does not change to the RGB (green) color it should? I have echo'd the $approvalcolor to the page AFTER the PDF generation and it does show as 34,139,34???

Upvotes: 0

Views: 817

Answers (2)

Ashutosh Yadav
Ashutosh Yadav

Reputation: 11

$approvalcolor = "34,139,34";
$colorArray = explode(',',$approvalcolor);
$pdf->SetTextColor($colorArray[0],$colorArray[1],$colorArray[2]);

Upvotes: 1

gillweb
gillweb

Reputation: 91

ugh seems so easy now

switch ($decision) {
    case "Case1":
        $pdf->SetTextColor(34,139,34);
        break;
    case "Case2":
        $pdf->SetTextColor(34,139,34);
        break;
    case "Case3":
        $pdf->SetTextColor(255,0,0);
        break;
    case "Case4":
        $pdf->SetTextColor(65,105,225);
        break;
    default:
        $pdf->SetTextColor(0);
}

Upvotes: 0

Related Questions