I've been playing with FPDF and need to create a PDF using a starting template PDF so managed to get that figured out using FPDI. I then needed to use a non-standard font which I managed to get working as well. However... the letter spacing is all messed up (some letters tight together, others spaced way far apart in the same words).
I found the add on solution of FPDF_CellFit but that class extends FPDF so how can I make it work when using FPDI? Here is my code:
$pdf =& new FPDI();
$pdf->AddFont('AgencyFB-Reg','','agencyfbb.php');
$pdf->AddPage('mm', array(54,92));
$pdf->setSourceFile('test.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0, 92);
$pdf->SetFont('AgencyFB-Reg','',14);
$pdf->SetXY(100, 27);
$pdf->Write(0, "testing");
$pdf->Output();
But as explained above, when I look at the FPDF_CellFit class it starts this way:
$pdf = new FPDF_CellFit();
class FPDF_CellFit extends FPDF {
... ... ...
}
Please help... I am so close!
I have make a package to fix that problem. You have to keep the same PDF all the time. So when you add some effect to it, it must be the same all the time.
In fact, the decorator pattern is a good way to do this.
The decorator class
And I have made the class cleft in object like this
So now when you use it you create a PDF class which extends FPDF. So the pdf will be create and you can call the cellfit class which extends the decorator class and add in the constructor your PDF. So all the time you keep the same PDF.
Example
Use with composer, the seating project will be autoloader
The full package with example is here, in the lib folder I have made draw and cellfit in this object pattern.
lib for cellfit in object