Hello Samuli Tuomola
You are not the only one how missed it. but I needed it in C#. 
So I changed Your code to c# and it works. Thanks a lot

here the C# code:

in Htmlworker.cs
line 530
//--
              System.Collections.ArrayList CellWidths = new
System.Collections.ArrayList(); 
                IncTable table = null;
                while (true) 
                {
                    IElement obj = stack.Pop();
                    if (obj is IncCell) 
                    {
                      //  cells.Add(((IncCell)obj).Cell);
                      //-- begin
                      IncCell cell = (IncCell) obj; 
                      if(cell.GetWidth() > 0)
                        CellWidths.Add(cell.GetWidth());
                      cells.Add( cell.Cell);
                      //-- end
                    }
                    if (obj is IncTable) {
                        table = (IncTable)obj;
                        break;
                    }
                }
                table.AddCols(cells);
                //-- begin 
                if(CellWidths.Count > 0) 
                {
                  // cells come off the stack in reverse, naturally
                  CellWidths.Reverse();
                  int nWidthItems = CellWidths.Count;

                  int[] widths = new int[nWidthItems];
                  //for(int i= nWidthItems-1; i>-1; i--)
                  for(int i= 0; i< nWidthItems; i++)
                  {
                    widths[i] = ((int)CellWidths[i]);
                  
                  }
                    table.SetColWidths(widths);
                } 
                //-- end
                table.EndRow();
                stack.Push(table);
                skipText = true;
                return;
            }

incCell.cs

 public class IncCell : ITextElementArray {
        
        private List<Chunk> chunks = new List<Chunk>();
        private PdfPCell cell;

        private int width=0;   //-- add this

line 95
if (value != null)
                cell.Padding = float.Parse(value,
System.Globalization.NumberFormatInfo.InvariantInfo);
            cell.UseDescender = true;
            value = props["bgcolor"];
            cell.BackgroundColor = Markup.DecodeColor(value);

          //--begin
            value = props["width"];
            if(value != null && value.EndsWith("%")) 
            {
             width = Convert.ToInt32(value.Replace("%", ""));
            } 
          //--end
  
line 150
 public bool IsNestable() {
            return true;
        }
      //--begin
      public int GetWidth() {
        return width;
      }
      public void SetWidth(int width) {
        this.width = width;
      } 
      //--end
        public override string ToString() {
            return base.ToString();
        }      

in IncTable.cs
public class IncTable : IElement {
        private Dictionary<string,string> props = new
Dictionary<string,string>();
        private List<List<PdfPCell>> rows = new List<List<PdfPCell>>();
        private List<PdfPCell> cols;

        private int[] colWidths; // added
    
line 85
 public List<List<PdfPCell>> Rows {
            get {
                return rows;
            }
        }
        //--begin
        public int[] GetColWidths() 
        { return colWidths; }
        
        public void SetColWidths(int[] colWidths) 
        {
          this.colWidths = colWidths;
        }
        //--end

line 120
 foreach (List<PdfPCell> col in rows) {
                foreach (PdfPCell pc in col) {
                    table.AddCell(pc);
                }
            }
          //-- begin
          try 
          {
            if(colWidths != null)
              table.SetWidths(colWidths);
            } catch (DocumentException e) 
            {
            // fail silently
          } 
          //--end
            return table;
        }


hope I havn't lost some code ;-)

Karl
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Re-HTMLWorker-table-cell-width-tp2169832p2258929.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to