iTextSharp table alignment

Posted by Kumar on Stack Overflow See other posts from Stack Overflow or by Kumar
Published on 2010-05-19T18:06:46Z Indexed on 2010/05/19 18:30 UTC
Read the original article Hit count: 859

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about itextsharp

Related posts about ASP.NET