gpt4 book ai didi

java - 自动换行 :break-word is not working with iText 2. 1.7

转载 作者:搜寻专家 更新时间:2023-11-01 02:50:42 28 4
gpt4 key购买 nike

我正在使用 JavaItext2.1.7 来生成 pdf 并且我编写了以下 HTML。但当它们太长时,它并不是断词。

String td ="<td colspan=\"2\" align=\"left\" style=\"table-layout: fixed;word-wrap:break-word;white-space: normal;\"><b>"
+ verylongwordverylongwordverylongword + ":</b></td>"

有人可以帮我实现这个目标吗?

最佳答案

Itext 2.7.1 不支持 word-wrap : break-word 属性。以下是该链接。

http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html

因此,我根据表的列数并假设最大字母在 60-65 左右来手动拆分单词。以下是相关代码。

public String getBrokenWordsForPdfGeneration(String longString, int cutIndex){
StringBuffer mainStringBuffer = new StringBuffer(longString);
String returnString = "";
while(mainStringBuffer != null && mainString.length()>0 &&
mainString.subString(0,mainString.length()>cutIndex?cutIndex:mainString.length()) != null){
if(mainStrig.subString(0,mainString.length()>cutIndex:mainString.length()).trim().contains(" ")){
returnString += mainStrig.subString(0,mainString.length()>cutIndex:mainString.length()).trim();
mainStringBuffer.delete(0,mainString.length()>cutIndex:mainString.length());
}else{
returnString += mainStrig.subString(0,mainString.length()>cutIndex:mainString.length()).trim()+ " ";
mainStringBuffer.delete(0,mainString.length()>cutIndex:mainString.length());
}
}
return returnString;
}

关于java - 自动换行 :break-word is not working with iText 2. 1.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11754085/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com