Html2pdf doesn't support word-break:break-all css
hai,每个人我都使用html2pdf,它不支持断字:break-all css有什么想法吗?
例
1 2 3 | <td style="width:30%;word-break:break-all ;"> testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets </td> |
输出pdf的宽度超过字符串长度大小的30%
输出pdf:testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets
我想要输出:
testtestetstetstetstetstettstets
tetstetstetstetstetstetstetstetstets
好吧,那很复杂。您的测试字符串太长,但是它不是由多个单词组成。这意味着断字是行不通的,因为没有任何要断的字。显然,这可能只是一个示例,在这种情况下,html2pdf可能不支持相对宽度和
就是说,这是我知道可以使用的东西:PHP中的自动换行。因此,可以使用
", true)
1 2 3 |
输出:
1 2 3 | testtesttesttesttest testtesttesttesttest testtest |
试试这个;
1 2 3 | <td style="width:30%; word-wrap:break-word;"> testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets </td> |
不是
如果您希望长字符串一致地包裹在边界容器中,我认为您应该能够通过在原始字符串的每个字母之间插入零宽度空格字符(
从而:
1 | testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets |
成为
1 | 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 |
(显示为:" tst te s t e ts s t t s t e s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s t s s t s t s s t s s t s s t s s t s t s s)
因此,如果将其包装,它将完全包装到其容器的边界。这是一个小例子。
只需编写一个PHP脚本来遍历字符串并插入空格:
1 2 3 4 5 6 7 8 9 | $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].""; } echo $new_string |
这是一个特别好的解决方案,因为与
同样,如果您需要使生成的PDF可搜索,这不是一个好方法,但是它将使它看起来像您想要的那样。
您只需在代码中使用substr函数。
我为此举了一个例子。首先将您的输出变量。
1 2 3 |
等等。
在您的测试中,单词break无效,因为单词break仅在特定句子中的单词之间起作用。因此,您可以使用多个单词的句子,然后尝试使用分词系统
您可以使用
\
"
html2pdf不支持断字:break-all CSS
参考:http://www.yaronet.com/zh-CN/posts.php?sl=&h=0&s=151321#0
我想对HTML2PDF和表格添加一些自己的经验。
我使用此解决方案生成了PDF,其中包含一个表格,该表格中填充有交货确认书(产品列表)。这样的列表可能包含多达数千个产品(行)。
我在单元格中遇到了格式化和长字符串的问题。第一个问题是即使我将表的宽度设置为100%且表头(
-
设置表格和每行的固定宽度(以像素为单位)
- 对于A4字母大小,我使用的总宽度为550像素,并带有默认边距,但您必须花一点时间才能在列之间分配宽度
-
在
wordwrap 中使用空格或 /\\xe2\\x80\\x8b 作为分隔符
对于您要散布100%可见区域宽度的小桌子,可以使用
您可以使用此方法。
1 2 3 4 5 6 |
我认为此功能是一种脚的解决方案。
1 2 3 4 5 6 7 8 9 10 11 12 |