Html2pdf doesn't support word-break:break-all css

srini picture srini · Oct 6, 2012 · Viewed 18k times · Source

hai everybody i am using html2pdf ,it doesn't support word-break:break-all css any idea?

example

   <td style="width:30%;word-break:break-all ;">
      testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets
    </td>

output pdf take above 30% width like string length size

output pdf: testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets

I want Output :

testtestetstetstetstetstettstets
tetstetstetstetstetstetstetstets

Answer

Berry Langerak picture Berry Langerak · Oct 8, 2012

Well, that's complicated. Your teststring is too long, but it's not composed of multiple words. That means that word-break won't work, because there aren't any words to break on. Obviously, this might well just be an example, in which case it might be that html2pdf just doesn't support relative widths and word-break, so you could try having an absolute width and word-break.

That said, here's something I know that will work: wordwrap in PHP. So, instead of echo $yourvar; you could use echo wordwrap($yourvar, 75, "\n", true) instead, which will always cut the string, even if it's just one long string. It takes a little fiddling to get the number of characters to match up with the width that you're looking for, but it will work.

<?php
$foo = str_repeat('test',12);
echo wordwrap($foo, 20, '<br />', true);

Output:

testtesttesttesttest
testtesttesttesttest
testtest