简体   繁体   中英

word-wrap:break-word is not working with iText 2.1.7

I am using Java & Itext2.1.7 for generating pdf and I have written the following HTML . But it is not breaking 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 achieving this?

Itext 2.7.1 does not support word-wrap : break-word property. Following is the link for that.

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

So I have manually break the words according to the no of columns of the Table and by taking assumption of maximum letters around 60-65.Following is the code for that.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM