Word-wrap: the word break does not work with iText 2.1.7

I use Java and Itext2.1.7 to create pdf , and I wrote the following HTML . But this is not a violation of words when they are too long.

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

Can someone help me with this?

+4
source share
1 answer

Itext 2.7.1 does not support the word-wrap: break-word property. Below is a link for this.

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

So, I manually broke the words into columns of the table and taking the maximum number of letters around 60-65. The following code for this.

 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; } 
+4
source

All Articles