Html2pdf does not support word-break: break-all css

hai everything i use html2pdf, it doesn't support word-break: break-all css any idea?

Example

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

pdf output takes up more than 30% of the width, as the size of the string length

pdf output: testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstetstetstets

I want Exit:

testtestetstetstetstetstettstetsstets
tetstetstetstetstetstetstetstetstets

+7
source share
10 answers

html2pdf does not support this word break: break-all css

Link: http://www.yaronet.com/en/posts.php?sl=&h=0&s=151321#0

+2
source

Well, that is complicated. Your test string is too long, but it does not consist of a few words. This means the word break will not work because there are no words to break. Obviously, this can be just an example, and in this case it may be that html2pdf just does not support relative widths and word-break , so you can try to have absolute widths and word-break .

However, here I know what will work: wordwrap in PHP. So instead of echo $yourvar; instead, you can use echo wordwrap($yourvar, 75, "\n", true) , which will always cut the line, even if it is only one long line. In order for the number of characters to match the width you are looking for, you need to play a little, but it will work.

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

Output:

 testtesttesttesttest testtesttesttesttest testtest 
+11
source

try it;

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

not word-break is word-wrap ;

+6
source

If you want long strings to be connected sequentially inside the boundary container, I think you can do this by inserting space characters without spaces ( &#8203; or \xe2\x80\x8b ) between each letter of the orignial string . This will have a wrapping effect, as if each character was its own word, but without displaying spaces to the end user. This can cause problems with text search or indexing of the final product, but it should perform the task reliably from an aesthetic point of view.

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: "testtssttttttttttttt test t t t t t t t t t t t t t t t t t t t t t et s ")

So, if you wrap it, it will be exactly bound to the borders of its container. Here is a scenario of this as an example .

Just write a PHP script to encode the line and insert a 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 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 is automatically configured for fonts of non-fixed widths (which basically makes up 99% of the fonts used).

Again, if you want the PDF file to be searchable, this is not a good approach, but it will make it look the way you want.

+5
source

In your testing, the word break will not work, because the word break only works between words in a specific sentence. So yo can use the multiple word sentence and then try using the word breaker

+4
source

You just use the substr function in your code. I gave an example for this. First put your result in a variable.

 $get_value = "testtestetstetstetstetstettstetstetstet"; $first = substr("$get_value",0,3); $second = substr("$get_value",4,7); 

etc.

+4
source

You can use "\r\n" to print a newline character. be sure to use it with a double quote. If your string is in a variable, you need to use the word count function and add this string. You can also use PHP_EOL to avoid platform dependency.

+3
source

You can use this method.

 <?php $get_value = "testtestetstetstetstetstettstetstetstet"; $first = substr("$get_value",0,3); $second = substr("$get_value",4,7); $third = substr("$get_value",8,11); ?> 
0
source

I want to add some personal experience with HTML2PDF and tables.

I used this solution to create a PDF file containing a delivery confirmation table (product list). Such a list can contain up to a thousand products (lines).

I am having a problem with formatting and long lines in cells. The first problem was that the table became too wide even if I set the table width to 100% and the width of the header columns ( <th> ) (HTML2PDF does not support <colgroup> , so I could not define it globally) - some columns were out of the visible area. I used wordwrap() with <br /> as a separator to break up long lines that looked like they were working. Unfortunately, it turned out that if there is such a long row in the first and last row, the whole table is added and added with a blank page. Not a real asshole, but he doesn't look handsome either. The final solution was that (applied to tables whose width can reach the visible area):

  • set a fixed table width and each row in pixels
    • for letter size A4 I use a total width of 550 pixels with the default, but you need to play a bit to distribute the width between the columns.
  • in wordwrap use white space or &#8203; / \xe2\x80\x8b as a delimiter

For small tables that you want to distribute for 100% of the visible width of the area, you can use the width, expressed in % .

0
source

I think this feature is a lame solution.

 function String2PDFString($string,$Length) { $Arry=explode(" ",$string); foreach($Arry as $Line) { if(strlen($Line)>$Length) $NewString.=wordwrap ($Line,$Length," ",true); else $NewString.=" ".$Line; } return $NewString; } 
-one
source

All Articles