Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 446
srini Avatar asked Oct 06 '12 11:10

srini


People also ask

Can I use word-Break Break all?

The “word-break: break-all;” will break the word at any character so the result is to difficulty in reading whereas “word-wrap: break-word;” will split word without making the word not break in the middle and wrap it into next line.

What is the Do not Break-word in CSS?

Wrap the words that you don't want to break. <p>This is my paragraph. It will wrap normally, except for the part about <span style="white-space:nowrap">happily-hyphenated-hillbillies</span>.

Is word-break deprecated?

Note: While word-break: break-word is deprecated, it has the same effect, when specified, as word-break: normal and overflow-wrap: anywhere — regardless of the actual value of the overflow-wrap property.

How do you break text in CSS?

A hard break ( ‐ ) will always break, even if it is not necessary to do so. A soft break ( &shy; ) only breaks if breaking is needed. You can also use the hyphenate-character property to use the string of your choice instead of the hyphen character at the end of the line (before the hyphenation line break).


2 Answers

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
like image 95
Berry Langerak Avatar answered Sep 22 '22 09:09

Berry Langerak


try this;

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

not word-break it is word-wrap ;

like image 37
avalkab Avatar answered Sep 24 '22 09:09

avalkab