Download iTextSharp.dll
Code
protected void Button1_Click(object sender, EventArgs e) { ExportToPDF(); } private void ExportToPDF() { Document MyDocumnet = new Document(PageSize.LEDGER, 30, 30, 30, 30); System.IOMemoryStream MyReport = new System.IOMemoryStream(); PdfWriter writer = PdfWriter.GetInstance(MyDocumnet, MyReport); MyDocumnet.AddAuthor("Aravind"); MyDocumnet.AddSubject("My Firsr Pdf"); MyDocumnet.Open(); string strImagePath = Server.MapPath("StudentsPhoto/6353878428761513791.gif"); iTextSharp.textTable tblHead = new iTextSharp.textTable(1) { WidthPercentage = 50 }; tblHead.Padding = 2; tblHead.Spacing = 0; iTextSharp.textImage imgLogo = iTextSharp.text.Image.GetInstance(strImagePath); Cell cellHead1 = new Cell(imgLogo); cellHead1.HorizontalAlignment = Element.ALIGN_CENTER; cellHead1.VerticalAlignment = Element.ALIGN_MIDDLE; cellHead1.Leading = 8; cellHead1.Colspan = 1; cellHead1.BackgroundColor = Color.LIGHT_GRAY; cellHead1.Border = Rectangle.NO_BORDER; tblHead.AddCell(cellHead1); Cell cellHead2 = new Cell(new Phrase("APPLICATION FOR ADMISSION TO B-TECH COURSE UNDER MANAGEMENT QUOTA",FontFactory.GetFont("Arial Narrow", 14, Font.BOLD + Font.UNDERLINE,Color.BLACK ))); cellHead2.HorizontalAlignment = Element.ALIGN_CENTER; cellHead2.VerticalAlignment = Element.ALIGN_MIDDLE; cellHead2.Leading = 8; cellHead2.Colspan = 1; cellHead2.BackgroundColor = Color.LIGHT_GRAY; cellHead2.Border = Rectangle.NO_BORDER; tblHead.AddCell(cellHead2); Cell cellHead3 = new Cell(new Phrase(" ")); cellHead3.HorizontalAlignment = Element.ALIGN_CENTER; cellHead3.VerticalAlignment = Element.ALIGN_MIDDLE; cellHead3.Leading = 8; cellHead3.Colspan = 1; cellHead3.BackgroundColor = Color.LIGHT_GRAY; cellHead3.Border = Rectangle.NO_BORDER; tblHead.AddCell(cellHead3); cellHead3 = new Cell(new Phrase(" ")); cellHead3.HorizontalAlignment = Element.ALIGN_CENTER; cellHead3.VerticalAlignment = Element.ALIGN_MIDDLE; cellHead3.Leading = 8; cellHead3.Colspan = 1; cellHead3.BackgroundColor = Color.LIGHT_GRAY; cellHead3.Border = Rectangle.NO_BORDER; tblHead.AddCell(cellHead3); MyDocumnet.Add(tblHead); iTextSharp.textTable tblStdDetails = new iTextSharp.textTable(4) { WidthPercentage = 50 }; tblStdDetails.Padding = 3; tblStdDetails.Spacing = 2; AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, "Application Number"); AddCell(tblStdDetails, ": " + lblApplicaionNo.Text); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, "Category"); AddCell(tblStdDetails,": Management"); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, "Name"); AddCell(tblStdDetails, ": " + lblFname.Text + " " + lblMidName.Text + " " + lblLastName.Text); AddCell(tblStdDetails, ""); string strAdress = lblHomeName.Text + "\n " + lblPo.Text + "\n " + lblPlace.Text + "\n " + lblDistrict.Text + "\n " + lblState.Text + "\n " + lblPo.Text; AddCell(tblStdDetails, ""); AddCell(tblStdDetails, "Address"); AddCell(tblStdDetails, ": " + strAdress); AddCell(tblStdDetails,""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, "Date"); AddCell(tblStdDetails, ": " + DateTime.Now.ToShortDateString()); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); AddCell(tblStdDetails, ""); MyDocumnet.Add(tblStdDetails); MyDocumnet.Close(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=MyPdf.pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(MyReport.ToArray()); Response.End(); } private void AddCell(iTextSharp.textTable tbl, string strData) { Cell MyCell = new Cell(new Phrase(strData, FontFactory.GetFont("Arial Narrow", 12, iTextSharp.text.Font.NORMAL))); MyCell.HorizontalAlignment = Element.ALIGN_LEFT; MyCell.VerticalAlignment = Element.ALIGN_TOP; MyCell.Leading = 8; MyCell.Colspan = 1; MyCell.Border = iTextSharp.text.Rectangle.NO_BORDER; tbl.AddCell(MyCell); }