I'm creating an FPDI PDF. This is what I do now:
libraries_load('fpdi');
$pdf = new FPDI();
$path = drupal_get_path('theme', 'xmed') . '/docs/verkocht_template.pdf';
$pdf->setSourceFile(realpath($path));
$tplIdx = $pdf->importPage(1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tplIdx, 0, 0, 210);
$path = drupal_get_path('theme', 'xmed') . '/fonts/lato.php';
$pdf->AddFont('lato-light-webfont','','lato-light-webfont.php');
$pdf->SetFont('lato-light-webfont', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetXY(47, 71);
$pdf->Write(0, $name);
I'm also placing some other variables on my PDF. This is the result now:
But as you can see the $name variable is to long... . I've tried this:
$naam = wordwrap($naam, 20);
But that gave me this result:
What would be the best solution to fix this?
Simply use MultiCell() instead of Write(). It allows you to define a width (1st parameter) on which the text will be wrapped automatically.