views:

270

answers:

1

alt text

I am generating some PDFs with dompdf, which contains some text and images in a table. But if the text has a large URL in it, the URL wraps all the way to the end of the line. All the text and URL are wrapped in a div with fixed width and height, yet the URL still overflows.

The same HTML rendered in the browser seems to be OK.

Any thoughts?

A: 

I believe DOMPDF is using a fairly limited character set for determining how to split a line. Right now it only splits a line at a dash or a space. So something like the URL you have in your sample is going to run past the width of the container. DOMPDF just doesn't know how to break it up. If you're comfortable hacking the code you can work around the problem pretty easily. Open up the file dompdf/include/text_frame_reflower.cls.php and fine the line that looks like the following:

$words = preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

Modify the regular expression to include whatever extra characters you think will make for a good line break. You might, for example, break URLs up on ?, &, or even / if you expect to have extremely long URLs in your text:

$words = preg_split('/([\s-\?\&\/]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
BrianS