Search code examples
phphtmlpdffpdf

How to change FPDF label format like this?


I want a FPDF label format like this enter image description here

but I am getting like this

enter image description here

            $pdf->SetFont(Arial,B,12);
            $addresstext = sprintf("%s \n", "$school");


            $pdf->Add_Label($addresstext);

            // Add secondary text in normal smaller font.
            $LabelX = $pdf->LabelX();
            $LabelY = $pdf->LabelY();
            $pdf->SetXY($LabelX,$LabelY);
            $pdf->SetFont(Arial,'',9);
            $secondtext = sprintf("\n %s \n %s\n %s ","$studen", "$class","$date");
            $pdf->MultiCell(94,7, $secondtext,0,'C');  // Prints bottom right of label.

The library I am using: http://www.fpdf.org/en/script/script29.php


Solution

  • Why are you using this script in the first place? So that the school name will be bold? If you don't need it to be bold, just for get the Label and use straight MultiCell.

    You aren't showing all of your code so I'm not sure how you are initializing the script call. It says that the units are in mm by default. You might try initializing with $units='in'.

    If that doesn't help, I would quit using the Label script and make an implementation of MultiCell that will allow you to change the font properties on each line. You can look at the MultiCell code in the fpdf.php file and make a new class to make small changes to MultiCell that will allow this.

    Let me know if you get to this an need help.

    class PDF extends FPDF {
        function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $myFontProps=null) {
            ...fill in details here
        }
    }