English 中文(简体)
iTextSharp : pdfPTable overlapping with other content
原标题:

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 ?

最佳回答

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.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签