2012-08-01 47 views
4

工作我使用的Java &Itext2.1.7產生PDF,我寫了下面的HTML。但是,當它們太長時,它不會打破言辭。自動換行:打破字沒有用的iText 2.1.7

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

有人可以幫助我實現這個目標嗎?

+0

break-word是一個css3屬性。 iText在從html轉換時是否完全支持css3,很難說文檔已關閉 – Woody 2012-08-01 08:45:33

+0

Thanks @Woody,由於您的評論,我確實知道IText不支持分詞。 – PVR 2012-08-02 06:13:46

回答

4

Itext 2.7.1不支持word-wrap:break-word屬性。以下是該鏈接。

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

所以我根據無表的列,並採取圍繞60-65.Following最大字母的假設是,該代碼手動打破的話。

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