Reputation: 55
I'm having issues with wordwrapping with Zend Framework2 PDF. I'm retrieving values from a database to write to a PDF template, but for simplicity's sake I just have a variable with a string:
$text = "ASDF ASDF ASDF ASDF ASDF ASDF ASDF";
$newtext = wordwrap($text, 20, "<br/>");
$page->drawText($newtext,50,50);
All this code is doing is inserting a
tag ever 20 characters:
ASDF ASDF ASDF ASDF<br/>ASDF ASDF ASDF
Any ideas, this can't be a limitation of ZF2 or ZendPDF can it?
Upvotes: 1
Views: 1462
Reputation: 55
Found some code that helped me solve it. Instead of trying to 1 drawText event to write a single string on multiple lines, you have to explode the string and loop through the array drawing each item on a line.
$line = 225;
$textChunk = wordwrap($text, 70, "\n");
foreach(explode("\n", $textChunk) as $textLine){
if ($textLine!=='') {
$page->drawText(strip_tags(ltrim($textLine)), 75, $line, 'UTF-8');
$line -=12;
}
}
Upvotes: 3