can you please help me to generate and download pdf document on buton click event
below code is giving error as path is not legal formate
- protected void btnGenerateCertificate_Click(object sender, System.EventArgs e)
- {
- string imageURL = Server.MapPath("../images/logo.png");
- iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
-
-
- jpg.ScaleToFit(25f, 25f);
-
-
-
- jpg.SpacingAfter = 1f;
- jpg.Alignment = Element.ALIGN_CENTER;
-
-
- Paragraph parag = new Paragraph("Road Construction Department", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE));
- Paragraph paradate;
- Paragraph subparag;
- parag.SpacingAfter = 1f;
- parag.Alignment = Element.ALIGN_CENTER;
-
- subparag = new Paragraph("Govt. of Jharkhand", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
-
- subparag.Alignment = Element.ALIGN_CENTER;
- string AppId = Session["ApplicantId"].ToString();
- string datetime = DateTime.Now.ToString("dd-MMM-yyyy-H-mm-ss");
- string filename = "Certificate_" + Session["ApplicantId"].ToString() + "_" + datetime + ".pdf";
- FileStream file = new FileStream(Server.MapPath("~/Certificate/") + filename, FileMode.Create, System.IO.FileAccess.Write);
-
- string param = AppId + "~" + filename;
- DataSet ds = BLobj.contractor_registration_Insert_Update_Certificate(connString, param);
- StringWriter sw = new StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(sw);
- printableArea_IA_IB_IS.RenderControl(hw);
- StringReader sr = new StringReader(sw.ToString());
- Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
- PdfWriter.GetInstance(pdfDoc, file);
- pdfDoc.Open();
- pdfDoc.Add(jpg);
- pdfDoc.Add(parag);
- pdfDoc.Add(subparag);
- HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
- MemoryStream ms = new MemoryStream();
- htmlparser.Parse(sr);
- pdfDoc.Close();
- file.Close();
- Response.Redirect("Summary_Application1.aspx");
- }