Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i set itextSharp PdfPTable column width

How can i set itextSharp PdfPTable column width

Scheduled Pinned Locked Moved C#
question
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devenv exe
    wrote on last edited by
    #1

    In the sample code below, how can i set varying column widths for each column individually? The DescriptionColumnName width is expected to be much wider than other columns and Col1Name is not expected to be equal to Col2Name in width?. Currently, all columns are being returned with the same column width, and the description column in most cases contains alot of free text, so i want to reduce the width of columns Col1Name & Col2Name and then increase DescriptionColumnName width.

     Document document;
     document.NewPage();
    
     System.Collections.ArrayList columnWidth = new System.Collections.ArrayList();
        for (int i = 0; i < this.dataTable.Columns.Count; i++)
        {
            if (i < 2)
            {
                columnWidth.Add(2f);
            }
            else
            {
                columnWidth.Add(1f);
            }
        }       
    
    float\[\] headerWidths = columnWidth.OfType().Select(w => (float)w).ToArray();
    
    PdfPTable tableHeader = new PdfPTable(3);
    tableHeader.AddCell(GetCell(Col1Name));
    tableHeader.AddCell(GetCell(Col2Name));
    tableHeader.AddCell(GetCell(DescriptionColumnName));
    
    tableHeader.SetWidths(headerWidths);
    tableHeader.HeaderRows = 1;
    
    PopulatePDFCell(tableHeader);
    document.Add(tableHeader);
    

    "Coming soon"

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups