How to set the cell width in itextsharp pdf creation

后端 未结 4 1643
广开言路
广开言路 2020-12-18 23:35

How can I set cell width and height in itextsharp pdf cell ceration using c#. I just use

cell.width = 200f;

But it should display the error

相关标签:
4条回答
  • 2020-12-18 23:39

    You don't set the width of a cell.

    you should set the width of the columns. And you can do that by applying them on the table object:

    float[] widths = new float[] { 1f, 2f };
    table.SetWidths(widths);
    

    The answer from Neha is to set the width of the table object

    more reference material here: http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables

    0 讨论(0)
  • 2020-12-18 23:48
    int  count=Gridview1.Columns.Count
    PdfPTable table = new PdfPTable(count);
    float[] columnWidths = new float[count];
    for (int v = 0; v < count; v++)
    {
        if (v == 0) { 
        columnWidths[v] = 10f;
        }
        else if (v == 2)
        {
            columnWidths[v] = 30f;
        }
        else if(v == 3)
        {
            columnWidths[v] = 15f;
        }
        else if(v == 4)
        {
            columnWidths[v] = 18f;
        }
        else if(v == 5|| v == 6|| v == 7)
        {
            columnWidths[v] = 22f;
        }
        else
        {
            columnWidths[v] = 20f;
        }
    }
    
    table.SetWidths(columnWidths);
    
    0 讨论(0)
  • 2020-12-18 23:56

    http://indaravind.blogspot.in/2009/02/itextsharp-table-column-width.html

    VB:

    Dim intTblWidth() As Integer = {12, 10, 26, 10}
    

    C#:

    int[] intTblWidth = { 12, 10, 26, 10 };
    
    0 讨论(0)
  • 2020-12-19 00:00

    cell.width = 200f; you have to put capital W on width correct is cell.Width = 200f;

    0 讨论(0)
提交回复
热议问题