I have the below code in my Magento store it adds the customers address to the invoice PDF\'s. Sometimes the lines of the address would be too long for the address labels so I a
Using wordwrap is a good start, but it won't get you all the way there. What you will likely want to do is do a separate call to $page->drawText
for each line.
So for example something like this.
$textChunk = wordwrap($value, 20, "\n");
foreach(explode("\n", $textChunk) as $textLine){
if ($textLine!=='') {
$page->drawText(strip_tags(ltrim($textLine)), 75, $line, 'UTF-8');
$line -=14;
}
}
And be aware that depending on where you have this on the pdf, it can get quite complex. For example, if the user can enter in as much text as they want into this section, you will also need to make sure that this text doesn't overrun into another section's text. By this I mean if you have this block of text just above another block of text, you need to push down the y-coordinates of the lower block as the number of lines created by wordwrap() increases