private void RenderPdf(StringWriter document) { var pdfDocument = new Document(); pdfDocument.Open(); var pdfWriter = PdfWriter.GetInstance(pdfDocument, engineContext.Response.OutputStream); pdfWriter.CloseStream = false; using (var reader = new XmlTextReader(new StringReader(document.ToString()))) { var parser = new XmlParser(); parser.Go(pdfDocument, reader); } pdfWriter.Close(); }
public void Render(ViewContext viewContext, TextWriter writer) { // generate view into string var sb = new System.Text.StringBuilder(); TextWriter tw = new System.IO.StringWriter(sb); _result.View.Render(viewContext, tw); var resultCache = sb.ToString(); // detect itext (or html) format of response XmlParser parser; using (var reader = GetXmlReader(resultCache)) { while (reader.Read() && reader.NodeType != XmlNodeType.Element) { // no-op } if (reader.NodeType == XmlNodeType.Element && reader.Name == "itext") parser = new XmlParser(); else parser = new HtmlParser(); } // Create a document processing context var document = new Document(); document.Open(); // associate output with response stream var pdfWriter = PdfWriter.GetInstance(document, viewContext.HttpContext.Response.OutputStream); pdfWriter.CloseStream = false; // this is as close as we can get to being "success" before writing output // so set the content type now viewContext.HttpContext.Response.ContentType = "application/pdf"; // parse memory through document into output using (var reader = GetXmlReader(resultCache)) { parser.Go(document, reader); } pdfWriter.Close(); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="file"></param> public static void Parse(IDocListener document, String file) { XmlParser p = new XmlParser(); p.Go(document, file); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="file"></param> public static void Parse(IDocListener document, XmlDocument xDoc) { XmlParser p = new XmlParser(); p.Go(document, xDoc); }
/// <summary> /// Parses a given XmlTextReader. /// </summary> /// <param name="document"></param> /// <param name="reader"></param> /// <param name="tagmap"></param> public static void Parse(IDocListener document, XmlTextReader reader, Hashtable tagmap) { XmlParser p = new XmlParser(); p.Go(document, reader, tagmap); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="file"></param> /// <param name="tagmap"></param> public static void Parse(IDocListener document, String file, Hashtable tagmap) { XmlParser p = new XmlParser(); p.Go(document, file, tagmap); }
/// <summary> /// Parses a given XmlTextReader. /// </summary> /// <param name="document"></param> /// <param name="reader"></param> public static void Parse(IDocListener document, XmlTextReader reader) { XmlParser p = new XmlParser(); p.Go(document, reader); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="file"></param> /// <param name="tagmap"></param> public static void Parse(IDocListener document, string file, string tagmap) { var p = new XmlParser(); p.Go(document, file, tagmap); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="file"></param> /// <param name="tagmap"></param> public static void Parse(IDocListener document, XmlDocument xDoc, XmlDocument xTagmap) { XmlParser p = new XmlParser(); p.Go(document, xDoc, xTagmap); }
public ActionResult Send(MailInvoice minvoice) { PaymentInvoice tempinvoice = new PaymentInvoice().GetInvoice(Session["invoiceid"].ToString(), Session["companyid"].ToString(), Session["userid"].ToString()); string data = tempinvoice.invoicedata; XDocument invoicedoc = new XDocument(); try { invoicedoc = XDocument.Parse(data); } catch { } Business.DataLayer bd = new Business.DataLayer(); bd.UpdateInvoice(Session["invoiceid"].ToString(), Session["userid"].ToString(), Session["companyid"].ToString(), "", Session["companyid"].ToString(), "invoice", "outbound", 5, invoicedoc.ToString()); string resultstring = ""; ViewData.Model = tempinvoice; ViewContext viewContext; using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "download"); viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); resultstring = sw.GetStringBuilder().ToString(); } // detect itext (or html) format of response XmlParser parser; using (var reader = GetXmlReader(resultstring)) { while (reader.Read() && reader.NodeType != XmlNodeType.Element) { // no-op } if (reader.NodeType == XmlNodeType.Element && reader.Name == "itext") parser = new XmlParser(); else parser = new HtmlParser(); } // Create a document processing context var document = new Document(); document.Open(); // associate output with response stream string fname = Guid.NewGuid().ToString().Replace("-", ""); //var pdfWriter = PdfWriter.GetInstance(document, viewContext.HttpContext.Response.OutputStream); FileStream fs = new FileStream(Server.MapPath("/invoicebox/") + fname + ".pdf", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite); var pdfWriter = PdfWriter.GetInstance(document, fs); pdfWriter.CloseStream = false; // this is as close as we can get to being "success" before writing output // so set the content type now viewContext.HttpContext.Response.ContentType = "application/pdf"; // parse memory through document into output using (var reader = GetXmlReader(resultstring)) { parser.Go(document, reader); } pdfWriter.Close(); fs.Dispose(); document.Close(); MailMessage mail = new MailMessage(); mail.To.Add(minvoice.recipients); mail.To.Add("*****@*****.**"); mail.From = new MailAddress("*****@*****.**"); mail.Subject = minvoice.subject; //string url = "http://192.168.1.252/mexservices/sharingservices.svc/User/Confirm?email=" + HttpUtility.UrlEncode(email) + "&code=" + confirmationcode; string Body = minvoice.message; mail.Body = Body; mail.IsBodyHtml = true; mail.Attachments.Add(new Attachment(Server.MapPath("/invoicebox/" + fname + ".pdf"))); SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["smtphost"].ToString(); //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpusername"].ToString(), ConfigurationManager.AppSettings["smtppassword"].ToString()); //Or your Smtp Email ID and Password smtp.EnableSsl = true; smtp.Send(mail); return Redirect(Request.UrlReferrer.ToString()); }
public ActionResult SaveAsPdf() { PaymentInvoice tempinvoice = new PaymentInvoice().GetInvoice(Request.QueryString["tid"].ToString(), Session["companyid"].ToString(), Session["userid"].ToString()); string data = tempinvoice.invoicedata; XDocument invoicedoc = new XDocument(); try { invoicedoc = XDocument.Parse(data); } catch { } string resultstring = ""; ViewData.Model = tempinvoice; ViewContext viewContext; using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "download"); viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); resultstring = sw.GetStringBuilder().ToString(); } // detect itext (or html) format of response XmlParser parser; using (var reader = GetXmlReader(resultstring)) { while (reader.Read() && reader.NodeType != XmlNodeType.Element) { // no-op } if (reader.NodeType == XmlNodeType.Element && reader.Name == "itext") parser = new XmlParser(); else parser = new HtmlParser(); } // Create a document processing context var document = new Document(); document.Open(); // associate output with response stream //var pdfWriter = PdfWriter.GetInstance(document, viewContext.HttpContext.Response.OutputStream); FileStream fs = new FileStream(Server.MapPath("/invoicebox/") + Guid.NewGuid().ToString().Replace("-", "") + ".pdf", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite); var pdfWriter = PdfWriter.GetInstance(document, fs); pdfWriter.CloseStream = false; // this is as close as we can get to being "success" before writing output // so set the content type now viewContext.HttpContext.Response.ContentType = "application/pdf"; // parse memory through document into output using (var reader = GetXmlReader(resultstring)) { parser.Go(document, reader); } pdfWriter.Close(); fs.Dispose(); document.Close(); return Redirect(Request.UrlReferrer.ToString()); //var pdfdata = new PdfResultnew(tempinvoice, "download"); //Response.ClearContent(); //return pdfdata; }
/// <summary> /// Parses a given XmlTextReader. /// </summary> /// <param name="document"></param> /// <param name="reader"></param> /// <param name="tagmap"></param> public static void Parse(IDocListener document, XmlReader reader, string tagmap) { var p = new XmlParser(); p.Go(document, reader, tagmap); }
/// <summary> /// Parses a given file. /// </summary> /// <param name="document"></param> /// <param name="xDoc"></param> public static void Parse(IDocListener document, XmlDocument xDoc) { var p = new XmlParser(); p.Go(document, xDoc); }