Esempio n. 1
0
        private void ExportDivContentToPDF()
        {
            System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
            try
            {
                // create an API client instance
                string          userName = ConfigurationManager.AppSettings["pdfcrowdUsername"].ToString();
                string          APIKey   = ConfigurationManager.AppSettings["pdfcrowdAPIKey"].ToString();
                pdfcrowd.Client client   = new pdfcrowd.Client(userName, APIKey);

                // convert a web page and write the generated PDF to a memory stream
                MemoryStream Stream = new MemoryStream();
                //client.convertURI("http://www.google.com", Stream);

                // set HTTP response headers
                Response.Clear();
                Response.AddHeader("Content-Type", "application/pdf");
                Response.AddHeader("Cache-Control", "max-age=0");
                Response.AddHeader("Accept-Ranges", "none");
                Response.AddHeader("Content-Disposition", "attachment; filename=TigerReservePdfExport.pdf");
                System.IO.StringWriter       stringWrite1 = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite1   = new HtmlTextWriter(stringWrite1);
                MainContent.RenderControl(htmlWrite1);
                client.convertHtml(stringWrite1.ToString(), Stream);
                // send the generated PDF
                Stream.WriteTo(Response.OutputStream);
                Stream.Close();
                Response.Flush();
                Response.End();
            }
            catch (pdfcrowd.Error why)
            {
                Response.Write(why.ToString());
            }
        }
Esempio n. 2
0
        private void ExportDivContentToMsExcel()
        {
            try
            {
                StringBuilder StrHtmlGenerate = new StringBuilder();
                StringBuilder StrExport       = new StringBuilder();

                StrExport.Append(@"<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'><head><title>Time</title>");
                StrExport.Append(@"<body lang=EN-US style='mso-element:header' id=h1><span style='mso--code:DATE'></span><div class=Section1>");
                StrExport.Append("<DIV  style='font-size:12px;'>");
                System.IO.StringWriter       stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite   = new HtmlTextWriter(stringWrite);
                MainContent.RenderControl(htmlWrite);
                StrExport.Append(stringWrite);
                StrExport.Append("</div></body></html>");
                string strFile        = "QuarterlyReportExcelExport.xls";
                string strcontentType = "application/excel";
                Response.ClearContent();
                Response.ClearHeaders();
                Response.BufferOutput = true;
                Response.ContentType  = strcontentType;
                Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
                Response.Write(StrExport.ToString());
                Response.Flush();
            }
            catch (Exception ex)
            {
                LogHandler.LogFatal((ex.InnerException != null ? ex.InnerException.Message : ex.Message), ex, this.GetType());
            }
        }
Esempio n. 3
0
        private void ExportDivContentToMsWord()
        {
            try
            {
                Response.Clear();
                Response.Buffer = true;

                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);

                System.IO.StringWriter       stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite   = new HtmlTextWriter(stringWrite);
                MainContent.RenderControl(htmlWrite);

                //build the content for the dynamic Word document
                //in HTML alongwith some Office specific style properties.
                var strBody = new StringBuilder();

                strBody.Append("<html " +
                               "xmlns:o='urn:schemas-microsoft-com:office:office' " +
                               "xmlns:w='urn:schemas-microsoft-com:office:word'" +
                               "xmlns='http://www.w3.org/TR/REC-html40'>" +
                               "<head><title>Time</title>");

                //The setting specifies document's view after it is downloaded as Print
                //instead of the default Web Layout
                strBody.Append("<!--[if gte mso 9]>" +
                               "<xml>" +
                               "<w:WordDocument>" +
                               "<w:View>Print</w:View>" +
                               "<w:Zoom>100</w:Zoom>" +
                               "<w:DoNotOptimizeForBrowser/>" +
                               "</w:WordDocument>" +
                               "</xml>" +
                               "<![endif]-->");

                strBody.Append("<style>" +
                               "<!-- /* Style Definitions */" +
                               "@page Section1" +
                               "   {size:9.5in 10.0in; " +
                               "   margin:1.0in 1.25in 1.0in 1.25in ; " +
                               "   mso-header-margin:.5in; " +
                               "   mso-footer-margin:.5in; mso-paper-source:0;}" +
                               " div.Section1" +
                               "   {page:Section1;}" +
                               "-->" +
                               "</style></head>");

                strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +
                               "<div class=Section1>");
                strBody.Append(stringWrite);
                strBody.Append("</div></body></html>");

                //Force this content to be downloaded
                //as a Word document with the name of your choice
                Response.AppendHeader("Content-Type", "application/msword");
                Response.AppendHeader("Content-disposition", "attachment; filename=TigerReserveWordExport.doc");

                Response.Write(strBody.ToString());

                Response.Flush();
                Response.End();
            }

            catch (Exception ex)
            {
                LogHandler.LogFatal((ex.InnerException != null ? ex.InnerException.Message : ex.Message), ex, this.GetType());
                Response.RedirectPermanent("~/ErrorPage.aspx", false);
            }
        }