Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Fetchdata()
- {
- dlInvoiceData = new DLInvoiceData();
- var invoiceDataset = dlInvoiceData.FetchInvoiceRecords(13);
- if (invoiceDataset.Tables.Count > 0)
- {
- var str = ReadInvoiceContent(invoiceDataset);
- if (!string.IsNullOrEmpty(str))
- {
- Document document = null;
- document = new Document();
- string FileName = DateTime.Now.ToString("ddmmyyyyhhmmss");
- string path = Server.MapPath("~") + "/Invoice/" + FileName + ".pdf";
- PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
- document.Open();
- iTextSharp.text.html.simpleparser.HTMLWorker hw =
- new iTextSharp.text.html.simpleparser.HTMLWorker(document);
- hw.Parse(new StringReader(str));
- document.Close();
- document.Dispose();
- Response.ContentType = "Application/pdf";
- Response.AppendHeader("Content-Disposition", "attachment; filename=Voucher.pdf");
- Response.TransmitFile(path);
- //Response.OutputStream();
- Response.End();
- }
- }
- }
- private string ReadInvoiceContent(DataSet dataset)
- {
- try
- {
- var _content = string.Empty;
- using (StreamReader reader = new StreamReader(Server.MapPath("~/Invoice/invoice.html")))
- {
- _content = reader.ReadToEnd();
- }
- if (_content != null)
- {
- _content = _content.Replace("{Demo}", dataset.Tables[0].Rows[0]["name"].ToString());
- return _content;
- }
- else
- return null;
- }
- finally
- {
- }
- }
Add Comment
Please, Sign In to add comment