This class can be used to parse an XML file.
コード例 #1
0
ファイル: PdfReturnBinder.cs プロジェクト: Eilon/spark
        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();
        }
コード例 #2
0
ファイル: PdfView.cs プロジェクト: hbopuri/RazorPDF
        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();
        }
コード例 #3
0
ファイル: XmlParser.cs プロジェクト: bmictech/iTextSharp
 /// <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);
 }
コード例 #4
0
ファイル: XmlParser.cs プロジェクト: bmictech/iTextSharp
 /// <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);
 }
コード例 #5
0
ファイル: XmlParser.cs プロジェクト: bmictech/iTextSharp
 /// <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);
 }
コード例 #6
0
ファイル: XmlParser.cs プロジェクト: bmictech/iTextSharp
 /// <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);
 }
コード例 #7
0
ファイル: XmlParser.cs プロジェクト: bmictech/iTextSharp
 /// <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);
 }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        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());
        }
コード例 #14
0
        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;
        }
コード例 #15
0
        /// <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);
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <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);
        }