2014-01-21 177 views
0

我正在使用itextsharp將html表格轉換爲pdf。在PDF中設置表格單元格的寬度ITextSharp

它工作正常,但寬度屬性不工作在PDF中。意思是當你改變表格的列寬度時,將它固定爲20%或20px,但不反映在PDF上。

如何在PDF中設置列的寬度?

我的代碼:

"<table border='1'>" 
    + "<thead><tr>" 
     + "<th style='width:10%;'>ID</th>" 
     + "<th style='width:70%;'>Testing Point</th>" 
     + "<th style='width:20%;'>Notes</th>" 
    + "</tr></thead></table>" 

上面的代碼顯示具有邊框,但PDF的總寬度表分爲3個部分。每個單元格取相同的寬度。

我如何修復表的寬度,以便它將採取用戶定義的列寬。

請幫助

感謝

+0

可能重複[iTextSharp的不關心我的html樣式(http://stackoverflow.com/questions/17918642/itextsharp-does-not-care-my-html-styles) –

回答

2

必須每排設置TD寬度百分比TD,不僅在標題行。的

<table width="75%"> 
    <tr> 
    <th scope="col" width="10%">&nbsp;</th> <th scope="col">&nbsp;</th> 
    </tr> 
    <tr> 
    <td width="10%">&nbsp;</td> <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td width="10%">&nbsp;</td> <td>&nbsp;</td> 
    </tr> 
</table> 
+0

這個工作.. ...我們必須爲每個td設置寬度 – Patel