最后一个单元格边框出现在表格的末尾

时间:2013-04-23 11:13:21

标签: c# asp.net pdf itextsharp

大家好我正在尝试使用itext创建一个pdf sharp.i创建了一个Pdftable并添加了另一个pdf表。问题是添加的pdf表的最后一个单元格的边框位于底部。这就是任何属性我可以添加以防止最后一个单元格的边框被拖到底部。 以下是我的代码

      PdfPTable MainTable = new PdfPTable(2);
      MainTable.ElementComplete = false;
      MainTable.ExtendLastRow = false;
      MainTable.WidthPercentage = 105f;
      float[] widthh = new float[] { 50f, 55f };
      MainTable.SetWidths(widthh);
      MainTable.HorizontalAlignment = Element.ALIGN_CENTER;
     MainTable.SpacingBefore = 5f;

    PdfPTable Itms = new PdfPTable(2);
    float[] width = new float[] { 80f, 20f };
    Itms.SetWidths(width);
    Itms.HorizontalAlignment = iTextSharp.text.Image.ALIGN_TOP;
    Itms.ElementComplete = false;
    Itms.ExtendLastRow = false;
    Itms.DefaultCell.BorderColor = iTextSharp.text.BaseColor.BLACK;
    Itms.DefaultCell.BorderWidthBottom = 1;
    Itms.DefaultCell.BorderWidthTop = 1; 
    PdfPCell PdfPCell = null;

    //Add Header of the pdf table
    PdfPCell = new PdfPCell(new Phrase(new Chunk("Items", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8, iTextSharp.text.BaseColor.BLACK))));
    PdfPCell.Border = iTextSharp.text.Rectangle.BOTTOM_BORDER;
    Itms.AddCell(PdfPCell);

    PdfPCell = new PdfPCell(new Phrase(new Chunk("Orderderd before", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8, iTextSharp.text.BaseColor.BLACK))));
    PdfPCell.Border = iTextSharp.text.Rectangle.BOTTOM_BORDER;
    Itms.AddCell(PdfPCell);



    DataTable Excep = GetDatatable();
    //How add the data from datatable to pdf table
    for (int rows = 0; rows < Excep.Rows.Count; rows++)
    {
        for (int column = 0; column < Excep.Columns.Count; column++)
        {

            if ((column == 0) || (column == 2) || (column == 3))
            {
                PdfPCell = new PdfPCell(new Phrase(new Chunk(Excep.Rows[rows][column].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 6, iTextSharp.text.BaseColor.BLACK))));

                if (rows % 2 != 0)
                    PdfPCell.BackgroundColor = iTextSharp.text.BaseColor.LIGHT_GRAY;    
                Itms.AddCell(PdfPCell);
            }
        }
    }

     MainTable.AddCell(Itms);

enter image description here

0 个答案:

没有答案
相关问题