I have used the following code to fill my PdfPTable:
public PdfPTable GetTable(List<hsp_Narudzbe_IzdavanjeFakture4_Result> proizvodi)
{
PdfPTable table = new PdfPTable(5);
table.WidthPercentage = 100F;
table.DefaultCell.UseAscender = true;
table.DefaultCell.UseDescender = true;
Font f = new Font(Font.FontFamily.HELVETICA, 13);
f.Color = BaseColor.WHITE;
PdfPCell cell = new PdfPCell(new Phrase("Stavke narudžbe: ", f));
cell.BackgroundColor = BaseColor.BLACK;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.Colspan = 5;
table.AddCell(cell);
for (int i = 0; i < 2; i++)
{
table.AddCell("Redni broj");
table.AddCell("Proizvod");
table.AddCell("Cijena");
table.AddCell("Šifra proizvoda");
table.AddCell("Kolicina");
}
table.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
table.HeaderRows = 3;
table.FooterRows = 1;
int broj = 0;
table.DeleteLastRow();
foreach (hsp_Narudzbe_IzdavanjeFakture4_Result p in proizvodi)
{
broj++;
table.AddCell(broj.ToString());
table.AddCell(p.Naziv);
table.AddCell(p.Cijena);
table.AddCell(p.Sifra);
table.AddCell(p.Kolicina.ToString());
}
float[] widths = { 15.00F, 15.00F,15.00F,15.00F};
table.GetRow(1).SetWidths(widths);
return table;
}
Little explanation of code:
broj++; represents the row number which gets incremented each time a new row is added. That way I get the number for each row.
Now my question is: how can I manipulate width of the first column (which represents the row number). I have tried the following code:
float[] widths = { 15.00F, 15.00F,15.00F,15.00F};
table.GetRow(1).SetWidths(widths);
Can someone help me out with this ?