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

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

try this;

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

not word-break it is word-wrap ;


If you want long strings to wrap consistently within a boundary container I think you should be able to accomplish this by inserting zero-width space characters (&#8203; or \xe2\x80\x8b) between every letter of the orignial string. This will have the effect of wrapping as if every character was its own word, but without displaying the spaces to the end user. This may cause you trouble with text searches or indexing on the final product, but it should accomplish the task reliably from an aesthetic perspective.

Thus:

testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets

Becomes

t&#8203;e&#8203;s&#8203;t&#8203;t&#8203;e&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s

(which displays: "t​e​s​t​t​e​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s")

So if you wrap it it will wrap exactly to the bounds of its container. Here's a fiddle of it as an example.

Just write a PHP script to loop though the string and insert the space:

$string="testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets";
$new_string = "";
for($i=0;$i<strlen($string);$i++){
   if ($string[$i]==' ' || $string[$i+1]==' '){ //if it is a space or the next letter is a space, there's no reason to add a break character
      continue;
   }
   $new_string .= $string[$i]."&#8203;";
}
echo $new_string

This is a particularly nice solution, because unlike wordwrap(), it automatically adjusts for non-fixed-width fonts (which is basically 99% of fonts that are actually used).

Again, if you need to resulting PDF to be searchable, this is not a good approach, but it will make it look like you want it to.