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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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;
        }
    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.