I would like to propose a enhancement, if you allow me :bowtie:
There is a properties named word-wrap that works with word-break to break word preventing it to overflow the parent width, this property specifies line break opportunities within words.
For word-break Values have the following meanings:
normal : Break lines according to their usual rules.
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
break-all: Lines may break between any two characters within words. Hyphenation is not applied. This option is used mostly in a context where the text is predominantly using CJK characters with few non-CJK excerpts and it is desired that the text be better distributed on each line.
<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "<br />\n", true);
keep-all: Lines may break only at word separators and other explicit break opportunities. Otherwise this option is equivalent to ‘normal’. This option is mostly used where the presence of word separator characters still creates line-breaking opportunities, as in Korean.
/**
* Based on @cmbuckley original function I implemented a function to wrap my texts with line break,
* in all cases this is the best function, fit the word base on width on the table cell.
* When the word is too long it will be break in a 2 lines also.
* Similar of this style: `style="word-wrap: break-word; word-break: break-all;"`
**/
<?php
function smart_wordwrap($string, $width = 75, $break = "<br>") {
// split on problem words over the line length
$pattern = sprintf('/([^ ]{%d,})/', $width);
$output = '';
$words = preg_split($pattern, $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($words as $word) {
// normal behaviour, rebuild the string
if (false !== strpos($word, ' ')) {
$output .= $word;
} else {
// work out how many characters would be on the current line
$wrapped = explode($break, wordwrap($output, $width, $break));
$count = $width - (strlen(end($wrapped)) % $width);
// fill the current line and add a break
$output .= substr($word, 0, $count) . $break;
// wrap any remaining characters from the problem word
$output .= wordwrap(substr($word, $count), $width, $break, true);
}
}
// wrap the final output
return wordwrap($output, $width, $break);
}
The result into a table cell of this last is it:
But as I'm applying a fixed width it on original string not on text value of
parsed on html2pdf class. It would be very useful if it respect the cell width(if defined) to break the words into lines to prevent table overflow.
automatic break line is already there in HTML2PDF, it uses "usual rules", it doest not break words.
Breaking words is too dongerous, and it is not the solution for me : if your content does not fiit on your container => then the pb is maybe the container ...
you are creating a PDF for important document, cutting word automatically is not the solution.
Hello, and sorry for a new opening on it. But break words is an implemented CSS feature. So why not alloawing it here with the "word-break" css feature ?
Hello, and sorry for a new opening on it. But break words is an implemented CSS feature. So why not alloawing it here with the "word-break" css feature ?
yeah, for ex i have long filename some_long_filename_20210702_somehashcodehere_anotherlongtext.json
I would like to propose a enhancement, if you allow me :bowtie:
There is a properties named
word-wrap
that works withword-break
to break word preventing it to overflow the parent width, this property specifies line break opportunities within words.For
word-break
Values have the following meanings:normal
: Break lines according to their usual rules.break-all
: Lines may break between any two characters within words. Hyphenation is not applied. This option is used mostly in a context where the text is predominantly using CJK characters with few non-CJK excerpts and it is desired that the text be better distributed on each line.keep-all
: Lines may break only at word separators and other explicit break opportunities. Otherwise this option is equivalent to ‘normal’. This option is mostly used where the presence of word separator characters still creates line-breaking opportunities, as in Korean.The result into a table cell of this last is it:
But as I'm applying a fixed width it on original string not on text value of
automatic break line is already there in HTML2PDF, it uses "usual rules", it doest not break words.
Breaking words is too dongerous, and it is not the solution for me : if your content does not fiit on your container => then the pb is maybe the container ...
you are creating a PDF for important document, cutting word automatically is not the solution.
sorry, but i will not implement this.
Hello, and sorry for a new opening on it. But break words is an implemented CSS feature. So why not alloawing it here with the "word-break" css feature ?
yeah, for ex i have long filename
some_long_filename_20210702_somehashcodehere_anotherlongtext.json