Jump to content

Can you use color or font size in the sprintf() function?


suttercain

Recommended Posts

Thanks Barrand,

 

My idea fell flat. I am using the sprintf to output text to a PDF document. I was hoping the color would change the text in the document. It instead printed the entire as a string.

 

I even tried changing the color via the font tag:

 

$pdf = new PDF_Label('5160', 'in', 1, 2);

$pdf->Open();
$pdf->AddPage();

$sql = mysql_query("SELECT firmTitle, attendee FROM attendees") or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
// Print labels
	$trialNerror = "<font color='red'>".strtoupper($row['attendee'])."</font>";
    $pdf->Add_PDF_Label(sprintf("%s\n%s\n", $trialNerror, $row['firmTitle']));

}
$pdf->Output();

 

No luck. Anyone know if there is a PHP function to set the font size/text? I don't think there is, but it would be cool.

 

SC

Hi bluesky,

 

yeah I got that working with the FPDF calss as well as the extender PDF_Label.php

 

My problem is I am not able to output two different font sizes even when using the two different functions...

 

<?php
$pdf = new PDF_Label('5160', 'in', 1, 2);
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);

$pdfsm = new PDF_Label('5160', 'in', 1, 2);
$pdfsm->Open();
$pdfsm->AddPage();
$pdfsm->SetFont('Arial','B',12);
$sql = mysql_query("SELECT firmTitle, attendee FROM attendees") or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
// Print labels


	$trialNerror = strtoupper($row['attendee']);
    $pdf->Add_PDF_Label(sprintf("%s\n", $trialNerror));
$pdfsm->Add_PDF_Label(sprintf("%s", $row['firmTitle']));

}
$pdf->Output();
$pdfsm->Output();
?>

 

When I run the above code, only the $pdf->Output(); shows up. If I remove the $pdf->Output(); the $pdfsm->Output(); will show.

 

Any suggestions? Thanks.

I am not too familer with classes and would not know how to do this. I do know that I need the $row['attendee'] result to be a bigger font than the $row['FirmTitle'] result. I just have no idea how to do this.

 

If you know it would be greatly appreciated. Thanks.

 

SC

Are you trying to create labels with attendee in large letters over firm title under attendee in smaller letters? If so, I don't think you're going to get there with this class. The way you are heading, you will end up with a page of labels with attendee name and another page with firm title. This class isn't too flexible.

This is the current code I am using which outputs fine, but both lines of text are the same font size...

 

$pdf = new PDF_Label('5160', 'in', 1, 2);
$pdf->Open();
$pdf->AddPage();
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',12);

$sql = mysql_query("SELECT firmTitle, attendee FROM attendees") or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
// Print labels

    $pdf->Add_PDF_Label(sprintf("%s\n%s\n", $row['attendee'], $row['firmTitle']));

}
$pdf->Output();
?>

Hi Barrand,

 

Thanks for the advice. I have been playing with the function within the class and can't seem to grasp it.

 

function Add_PDF_Label($texte) {
        // We are in a new page, then we must add a page
        if (($this->_COUNTX ==0) and ($this->_COUNTY==0)) {
            $this->AddPage();
        }

        $_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space));
        $_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space));
        $this->SetXY($_PosX+3, $_PosY+3);
        $this->MultiCell($this->_Width, $this->_Line_Height, $texte);
        $this->_COUNTY++;

        if ($this->_COUNTY == $this->_Y_Number) {
            // End of column reached, we start a new one
            $this->_COUNTX++;
            $this->_COUNTY=0;
        }

        if ($this->_COUNTX == $this->_X_Number) {
            // Page full, we start a new one
            $this->_COUNTX=0;
            $this->_COUNTY=0;
        }
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.