views:

556

answers:

1

I am using iTextSharp to create a pdf in my ASP.NET 3.5 application. Below is the current layout of my pdf:

John Doe   EmployeeID 2008      Department1
                                                       Department2
                                                       Department3

Below is the code I am using:

PdfPTable table = new PdfPTable(4);
    table.DefaultCell.Border = 0;
    var empName = new Phrase("John Doe");
    var empIDHeading = new Phrase("EmployeeID");
    var empID = new Phrase("2008");
    var departments = new PdfPCell(CreateDepartments())
                     {
                         Border = 0,
                         NoWrap = true

                     };
    table.AddCell(empName);
    table.AddCell(empIDHeading );
    table.AddCell(empID );
    table.AddCell(departments);

 private PdfPTable CreateDepartments()
   {
      var d1 = new Phrase("Department1");
      var d2 = new Phrase("Department2");
      var d3 = new Phrase("Department3");
      PdfPTable table = new PdfPTable(2);
      table.DefaultCell.Border = 0;
      table.AddCell(d1);
      table.AddCell(d2);
      table.AddCell(d3);
      return table;
   }

How can I modify this code to get the below output:

                                                       Department1
                                                       Department2
John Doe   EmployeeID 2008      Department3

A: 

Set your PdfPTable's DefaultCell's VerticalAlignment property to Element.ALIGN_BOTTOM.

I added one line to your snippet showing this:

PdfPTable table = new PdfPTable(4); 
    table.DefaultCell.Border = 0; 
    // Added -----
    table.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM;

    var empName = new Phrase("John Doe"); 
    var empIDHeading = new Phrase("EmployeeID"); 
    var empID = new Phrase("2008"); 
    var departments = new PdfPCell(CreateDepartments()) 
                     { 
                         Border = 0, 
                         NoWrap = true 

                     }; 
    table.AddCell(empName); 
    table.AddCell(empIDHeading ); 
    table.AddCell(empID ); 
    table.AddCell(departments); 

Worked for me.

Jay Riggs