protected void Page_Load(object sender, EventArgs e) { ShowTable(""); } private void ShowTable(string p) { if (p.Equals("1")) { Document doc = new Document(); PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + "/1.pdf", FileMode.Create)); doc.AddTitle("PDF Title"); doc.AddSubject("PDF Subject"); doc.AddProducer(); //doc.AddKeywords("Add Keywords"); doc.AddHeader("Header Name,", "Header content"); doc.AddCreator("PDF Creator"); doc.AddCreationDate(); doc.AddAuthor("PDF Author"); doc.JavaScript_onLoad = "this is javascript load info!"; doc.JavaScript_onUnLoad = "pdf load done"; doc.AddKeywords("Add Keywords"); doc.Open(); doc.Add(new Paragraph("Hello World!!")); doc.Add(new Paragraph("Hello Worldsd!d!")); doc.Add(new Paragraph("Hello Worldsfsfs!!")); doc.Close(); Response.Redirect("~/1.pdf"); } else { Document doc = new Document(); PdfWriter pdf = PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + "/2.pdf", FileMode.Create)); iTextSharp.text.Table tab = new iTextSharp.text.Table(3);//3 columns tab.BorderWidth = 1; tab.BorderColor = new Color(0, 0, 255); tab.Padding = 3; tab.Spacing = 1; Cell cell = new Cell("header"); cell.Header = true; cell.Colspan = 3; tab.AddCell(cell); cell = new Cell("example cell with colspan 1 and rowspan 2"); cell.Rowspan = 2; cell.BorderColor = new Color(255, 0, 0); tab.AddCell(cell); tab.AddCell("1.1"); tab.AddCell("2.1"); tab.AddCell("1.2"); tab.AddCell("2.2"); tab.AddCell("cell test1"); cell = new Cell("big cell"); cell.Rowspan = 2; cell.Colspan = 2; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tab.AddCell(cell); tab.AddCell("Cell test2"); doc.Open(); doc.Add(tab); doc.Close(); Response.Redirect("~/2.pdf"); } }