views:

589

answers:

1

I am using iTextsharp to generate a PDF document from C# application. I am having a PdfPTable to display some tabular data. My problem in the table is overlapping with the other paragraph .Is there anyway i can place the table on a particular position ? then below is my code

        PdfPTable objTable = new PdfPTable(6);
        objTable.DefaultCell.Padding=1;
        objTable.DefaultCell.BorderColor = new Color(123, 123, 163);

        objTable.DefaultCell.Padding = 1;



        float[] headerwidths = { 12,18,25,20,6,17 }; // percentage
        objTable.SetWidths(headerwidths);
        objTable.WidthPercentage = 80; // percentage


        System.Drawing.Color objColor=System.Drawing.ColorTranslator.FromHtml("#EEEEEE");

        PdfPCell objCell0 = new PdfPCell(new Phrase("SlNo"));
        PdfPCell objCell1 = new PdfPCell(new Phrase("Date"));
        PdfPCell objCell2 = new PdfPCell(new Phrase("Expense name"));
        PdfPCell objCell3 = new PdfPCell(new Phrase("Budgeted value"));
        PdfPCell objCell4 = new PdfPCell(new Phrase("Units"));
        PdfPCell objCell5 = new PdfPCell(new Phrase("Total submitted"));


        //Add child rows with data
       List<SubmitExpenseItem> objItemList=objExpense.ExpenseChildItems;
       foreach (SubmitExpenseItem expChildItem in objItemList)
       {
           slno++;
           objTable.AddCell(new PdfPCell(new Phrase(slno.ToString())));
           objTable.AddCell(new PdfPCell(new Phrase(expChildItem.SubmitDate.ToShortDateString())));
           objTable.AddCell(new PdfPCell(new Phrase(expChildItem.ExpenseName)));
           objTable.AddCell(new PdfPCell(new Phrase(expChildItem.BudgetValue.ToString())));
           objTable.AddCell(new PdfPCell(new Phrase(expChildItem.Units.ToString())));
           objTable.AddCell(new PdfPCell(new Phrase(expChildItem.ActualValue.ToString())));              

       }

  objChildInfoPara.Add(objTable);

  objDoc.Add(objMasterDetailsPara);//First para
  objDoc.Add(objChildInfoPara);

Now my second para (objChildInfoPara) is overlapping with the first one

Can anyone tell me how to get rid of this problem ?

+1  A: 

Your code does not specify the content of objMasterDetailsPara. I assume it is defined elsewhere.

One problem I see is that your header cells ( objCell0...5 ) are never actually added to the pdf document. If objMasterDetailsPara is supposed to contain this column header information, that would explain your problem. It would look like the second paragraph was overlapping the first, when in fact the last part of the first paragraph was never actually added to the pdf document.

Stewbob