Guest User

Untitled

a guest
May 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. private void Fetchdata()
  2. {
  3. dlInvoiceData = new DLInvoiceData();
  4. var invoiceDataset = dlInvoiceData.FetchInvoiceRecords(13);
  5. if (invoiceDataset.Tables.Count > 0)
  6. {
  7. var str = ReadInvoiceContent(invoiceDataset);
  8. if (!string.IsNullOrEmpty(str))
  9. {
  10. Document document = null;
  11. document = new Document();
  12. string FileName = DateTime.Now.ToString("ddmmyyyyhhmmss");
  13.  
  14. string path = Server.MapPath("~") + "/Invoice/" + FileName + ".pdf";
  15. PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
  16. document.Open();
  17.  
  18. iTextSharp.text.html.simpleparser.HTMLWorker hw =
  19. new iTextSharp.text.html.simpleparser.HTMLWorker(document);
  20.  
  21.  
  22. hw.Parse(new StringReader(str));
  23. document.Close();
  24. document.Dispose();
  25.  
  26. Response.ContentType = "Application/pdf";
  27. Response.AppendHeader("Content-Disposition", "attachment; filename=Voucher.pdf");
  28. Response.TransmitFile(path);
  29. //Response.OutputStream();
  30. Response.End();
  31. }
  32. }
  33. }
  34.  
  35. private string ReadInvoiceContent(DataSet dataset)
  36. {
  37. try
  38. {
  39. var _content = string.Empty;
  40. using (StreamReader reader = new StreamReader(Server.MapPath("~/Invoice/invoice.html")))
  41. {
  42. _content = reader.ReadToEnd();
  43. }
  44. if (_content != null)
  45. {
  46. _content = _content.Replace("{Demo}", dataset.Tables[0].Rows[0]["name"].ToString());
  47.  
  48. return _content;
  49. }
  50. else
  51. return null;
  52. }
  53. finally
  54. {
  55.  
  56. }
  57. }
Add Comment
Please, Sign In to add comment