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;
}