1
Answer

pdf generation and downloading at button click event

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
  1. protected void btnGenerateCertificate_Click(object sender, System.EventArgs e)  
  2. {  
  3. string imageURL = Server.MapPath("../images/logo.png");  
  4. iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);  
  5.   
  6. //Resize image depend upon your need  
  7. jpg.ScaleToFit(25f, 25f);  
  8. //Give space before image  
  9. //jpg.SpacingBefore = 1f;  
  10. //Give some space after the image  
  11. jpg.SpacingAfter = 1f;  
  12. jpg.Alignment = Element.ALIGN_CENTER;  
  13.   
  14. //Header  
  15. 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));  
  16. Paragraph paradate;  
  17. Paragraph subparag;  
  18. parag.SpacingAfter = 1f;  
  19. parag.Alignment = Element.ALIGN_CENTER;  
  20.   
  21. 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));  
  22. //subparag.SpacingAfter = 1f;  
  23. subparag.Alignment = Element.ALIGN_CENTER;  
  24. string AppId = Session["ApplicantId"].ToString();  
  25. string datetime = DateTime.Now.ToString("dd-MMM-yyyy-H-mm-ss");  
  26. string filename = "Certificate_" + Session["ApplicantId"].ToString() + "_" + datetime + ".pdf";  
  27. FileStream file = new FileStream(Server.MapPath("~/Certificate/") + filename, FileMode.Create, System.IO.FileAccess.Write);  
  28. //save filename in database  
  29. string param = AppId + "~" + filename;  
  30. DataSet ds = BLobj.contractor_registration_Insert_Update_Certificate(connString, param);  
  31. StringWriter sw = new StringWriter();  
  32. HtmlTextWriter hw = new HtmlTextWriter(sw);  
  33. printableArea_IA_IB_IS.RenderControl(hw);  
  34. StringReader sr = new StringReader(sw.ToString());  
  35. Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);  
  36. PdfWriter.GetInstance(pdfDoc, file);  
  37. pdfDoc.Open();  
  38. pdfDoc.Add(jpg);  
  39. pdfDoc.Add(parag);  
  40. pdfDoc.Add(subparag);  
  41. HTMLWorker htmlparser = new HTMLWorker(pdfDoc);  
  42. MemoryStream ms = new MemoryStream();  
  43. htmlparser.Parse(sr);  
  44. pdfDoc.Close();  
  45. file.Close();  
  46. Response.Redirect("Summary_Application1.aspx");  
  47. }
Answers (1)
0
Satyapriya Nayak

Satyapriya Nayak

NA 53k 8m 11y
OLE DB is a set of COM-based interfaces that expose data from a variety of sources. OLE DB interfaces provide applications with uniform access to data stored in diverse information sources, or data stores. These interfaces support the amount of DBMS functionality appropriate to the data store, enabling the data store to share its data.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms722784%28v=vs.85%29.aspx

Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

http://msdn.microsoft.com/en-us/library/vstudio/bb397926.aspx
Accepted