Esempio n. 1
0
        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();

            var ms = new MemoryStream();
            var document = new Document();
            var pdfWriter = PdfWriter.GetInstance(document, ms);
            var worker = new HTMLWorker(document);
            document.Open();
            worker.StartDocument();

            pdfWriter.CloseStream = false;

            worker.Parse(new StringReader(resultCache));
            worker.EndDocument();
            worker.Close();
            document.Close();

            // 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";
            pdfWriter.Flush();
            pdfWriter.Close();

            viewContext.HttpContext.Response.BinaryWrite(ms.ToArray());
        }
        private void exportpdf()
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=BillReceipt.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            Panel1.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 100f, 10f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
    protected void BTNPDF_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Student.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.RenderControl(hw);
        StringReader sr         = new StringReader(sw.ToString());
        Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
Esempio n. 4
0
        private void ExportPDF(Control view)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Report.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            view.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     document   = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker   htmlWorker = new HTMLWorker(document);

            PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            htmlWorker.Parse(sr);
            document.Close();
            Response.Write(document);
            Response.End();
        }
Esempio n. 5
0
    private void ExportPdf()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=OrderInvoice.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();     //whole table/gridview in SW
        HtmlTextWriter hw = new HtmlTextWriter(sw); //attached with the StringBuilder

        Panel1.RenderControl(hw);
        StringReader sr         = new StringReader(sw.ToString());
        Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
        HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr); //parse html available inside the string
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
        public static void ExportToPdf(this DataTable dt, string FileName)
        {
            GridView GridView1 = new GridView();

            GridView1.AllowPaging = false;
            //GridView1.HeaderStyle.BackColor = System.Drawing.Color.Black;
            //GridView1.HeaderStyle.ForeColor = System.Drawing.Color.White;
            GridView1.HeaderStyle.Font.Bold = true;
            GridView1.HeaderStyle.Font.Size = 12;
            GridView1.Font.Size             = 10;
            GridView1.DataSource            = dt;
            GridView1.DataBind();
            GridView1.HeaderRow.BackColor = System.Drawing.Color.Blue;
            GridView1.HeaderRow.ForeColor = System.Drawing.Color.White;
            GridView1.HeaderRow.Font.Bold = true;
            GridView1.Style.Add("width", "100");
            if (string.IsNullOrEmpty(FileName))
            {
                FileName = "Pdf";
            }
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-disposition",
                                                   "attachment;filename=" + FileName + ".pdf");
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            GridView1.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            HttpContext.Current.Response.Write(pdfDoc);
            HttpContext.Current.Response.Flush();                // Sends all currently buffered output to the client.
            HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client.
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        protected void btnGrammar_Click(object sender, EventArgs e)
        {
            Random r   = new Random();
            int    num = r.Next();

            lblGrammer.Visible  = true;
            lblGrammer2.Visible = true;
            lbGhere.Visible     = true;
            Panel2.Visible      = true;
            lblGrammar.Visible  = true;

            lblGrammar.Text      = txtGrammar.Text;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=AEReccommendations" + num.ToString() + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   swe = new StringWriter();
            HtmlTextWriter hwe = new HtmlTextWriter(swe);

            Panel2.RenderControl(hwe);
            StringReader sr         = new StringReader(swe.ToString());
            Document     pdfDocGram = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDocGram);

            PdfWriter.GetInstance(pdfDocGram, Response.OutputStream);
            pdfDocGram.Open();
            htmlparser.Parse(sr);
            pdfDocGram.Close();
            Response.Write(pdfDocGram);

            txtGrammar.Text = "";
            lblGrammar.Text = "";



            Response.End();
            Panel2.Visible      = false;
            lblGrammar.Visible  = false;
            lblGrammer2.Visible = false;

            //pnFeedbackGrammar.Visible = true;
        }
Esempio n. 8
0
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime date    = DateTime.Today;
                string   pdfName = "disbursement_/" + date.ToString("dd/MM/yyyy");

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=" + pdfName + ".pdf");

                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                disbursementGV.AllowPaging = false;
                disbursementGV.DataSource  = Session["items"];
                disbursementGV.DataBind();
                disbursementGV.GridLines = GridLines.Both;
                HtmlForm frm = new HtmlForm();

                disbursementGV.Parent.Controls.Add(frm);
                frm.Attributes["runat"] = "server";
                frm.Controls.Add(collectionPoint);
                frm.Controls.Add(disbursementGV);
                frm.RenderControl(hw);

                StringReader sr         = new StringReader(sw.ToString());
                Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                string date    = DateTime.Parse(lblDate.Text.Trim()).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
                string pdfName = "InventoryStatus/" + date;

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=" + pdfName + ".pdf");

                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                inventoryReportGV.AllowPaging = false;
                inventoryReportGV.DataSource  = bl.getInventoryList();
                inventoryReportGV.DataBind();
                inventoryReportGV.GridLines = GridLines.Both;
                HtmlForm frm = new HtmlForm();
                inventoryReportGV.Parent.Controls.Add(frm);
                frm.Attributes["runat"] = "server";
                frm.Controls.Add(lblTitle);
                frm.Controls.Add(lblDate);
                frm.Controls.Add(inventoryReportGV);
                frm.RenderControl(hw);

                StringReader sr         = new StringReader(sw.ToString());
                Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
        }
Esempio n. 10
0
        //detailed report
        protected void Button5_Click(object sender, EventArgs e)
        {
            Paragraph para2 = new Paragraph("Fresh Course PVT LTD", FontFactory.GetFont("Arial", 30, iTextSharp.text.Font.BOLD));

            para2.Alignment = Element.ALIGN_CENTER;
            Paragraph para = new Paragraph("Order Details Report", FontFactory.GetFont("Arial", 20, iTextSharp.text.Font.BOLD));

            para.Alignment = Element.ALIGN_CENTER;
            Paragraph para3 = new Paragraph("Suhurupaya,Battaramulla Tel:0772825549", FontFactory.GetFont("Arial", 15, iTextSharp.text.Font.BOLD));

            para3.Alignment = Element.ALIGN_CENTER;
            iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("D:/Restaurant Management System/Restaurant Management System/Images/logo.png");
            png.ScaleToFit(200f, 200f);
            png.Alignment = Element.ALIGN_CENTER;
            Paragraph para1 = new Paragraph(" ", FontFactory.GetFont("Arial", 20, iTextSharp.text.Font.BOLD));

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=OrderReport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            GridView2.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            pdfDoc.Add(para2);
            pdfDoc.Add(para);
            pdfDoc.Add(para3);
            pdfDoc.Add(png);
            pdfDoc.Add(para1);
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
            GridView2.AllowPaging = true;
            GridView2.DataBind();
        }
Esempio n. 11
0
        protected void btnPDF_Click1(object sender, EventArgs e)
        {
            try
            {
                //lnkDwnloadPDF.Enabled = true;
                string CurrentDate = Convert.ToDateTime(lblDate2.Text).ToString("MM-dd-yyyy") + Convert.ToDateTime(lblDate2.Text).ToString("hhmmsstt");
                string Location    = Session["LocationName"].ToString();
                string PayrollDate = "PAYROLL REPORT " + lblWeekPayrollReport.Text;
                string filepath    = Server.MapPath("~/Payroll/" + Location + "/" + CurrentDate + "/");
                if (!System.IO.Directory.Exists(filepath))
                {
                    System.IO.Directory.CreateDirectory(filepath);
                }
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                dvpayrollreport.RenderControl(hw);
                StringReader sr         = new StringReader(sw.ToString());
                Document     pdfDoc     = new Document(new Rectangle(1200f, 1800f));
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, new FileStream(filepath + "Payroll.pdf", FileMode.Create));
                Session["FilePath"] = filepath + "Payroll.pdf";
                pdfDoc.Open();

                iTextSharp.text.Font georgia = FontFactory.GetFont("georgia", 20f, 1, new BaseColor(System.Drawing.Color.Brown));
                //georgia.Color = Color.Gray;
                Chunk  beginning = new Chunk(PayrollDate, georgia);
                Phrase p1        = new Phrase(beginning);
                Phrase p2        = new Phrase();
                pdfDoc.Add(new Paragraph(p1));
                //pdfDoc.Add(new Paragraph(30f, "Created at" + Convert.ToDateTime(lblDate2.Text).ToString("MM/dd/yyyy hh:mm:ss tt") + " by " + Session["EmpName"].ToString().Trim()));
                //pdfDoc.AddTitle(PayrollDate);
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                showpdf(Session["FilePath"].ToString());
                Response.End();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 12
0
        public byte[] RenderPDF(string htmlText /*, string pageTitle*/)
        {
            byte[] renderedBuffer;

            using (var outputMemoryStream = new MemoryStream())
            {
                using (var pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f))
                {
                    //string arialuniTff = Server.MapPath("~/fonts/ARIALUNI.TTF");
                    //FontFactory.Register(arialuniTff);

                    string Roboto = Server.MapPath("~/fonts/Roboto-Regular.ttf");
                    FontFactory.Register(Roboto);

                    PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);

                    pdfWriter.CloseStream = false;
                    //pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
                    pdfDocument.Open();

                    using (var htmlViewReader = new StringReader(htmlText))
                    {
                        using (var htmlWorker = new HTMLWorker(pdfDocument))
                        {
                            var styleSheet = new StyleSheet();
                            styleSheet.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Roboto-Regular");//Arial Unicode MS
                            styleSheet.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
                            htmlWorker.SetStyleSheet(styleSheet);

                            htmlWorker.Parse(htmlViewReader);
                        }
                    }
                }

                renderedBuffer = new byte[outputMemoryStream.Position];
                outputMemoryStream.Position = 0;
                outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
            }

            return(renderedBuffer);
        }
Esempio n. 13
0
        public static byte[] GetPDF(string pHTML)
        {
            byte[] bPDF = null;

            MemoryStream ms        = new MemoryStream();
            TextReader   txtReader = new StringReader(pHTML);

            // 1: create object of a itextsharp document class
            Document doc = new Document(PageSize.A4, 25, 25, 25, 25);

            // 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file
            PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);

            // 3: we create a worker parse the document
            HTMLWorker htmlWorker = new HTMLWorker(doc);

            StyleSheet styles = new StyleSheet();

            //styles.LoadTagStyle("th", "face", "helvetica");
            //styles.LoadTagStyle("span", "size", "10px");
            //styles.LoadTagStyle("span", "face", "helvetica");
            //styles.LoadTagStyle("td", "size", "10px");
            styles.LoadTagStyle("body", HtmlTags.FONTFAMILY, "times-roman");
            htmlWorker.SetStyleSheet(styles);

            // 4: we open document and start the worker on the document
            doc.Open();
            htmlWorker.StartDocument();

            // 5: parse the html into the document
            htmlWorker.Parse(txtReader);

            // 6: close the document and the worker
            htmlWorker.EndDocument();
            htmlWorker.Close();
            doc.Close();

            bPDF = ms.ToArray();

            return(bPDF);
        }
Esempio n. 14
0
        private void PdfExport(string filename)
        {
            var Text       = new StringBuilder();
            var pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            var htmlparser = new HTMLWorker(pdfDoc);

            using (var context = new Cabinet_MedicalEntities())
            {
                var query = from emp in context.Patients
                            select new
                {
                    emp.Nume,
                    emp.CNP,
                    emp.Serie_Buletin,
                    emp.Numar_Buletin,
                    emp.Data_Nasterii
                };


                foreach (var row in query)
                {
                    var newline = string.Format("{0},{1},{2},{3},{4},\r\n", row.Nume.ToString().Trim(),
                                                row.CNP.ToString().Trim(), row.Serie_Buletin.ToString().Trim(), row.Numar_Buletin.ToString().Trim(),
                                                row.Data_Nasterii.ToString().Trim());
                    Text.AppendLine(newline);
                }
            }
            using (var memory = new MemoryStream())
            {
                var writer = PdfWriter.GetInstance(pdfDoc, memory);
                pdfDoc.Open();

                htmlparser.Parse(new StringReader(Text.ToString()));
                pdfDoc.Close();

                byte[] bytes = memory.ToArray();
                File.WriteAllBytes(filename, bytes);

                memory.Close();
            }
        }
Esempio n. 15
0
    protected void print_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Event.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   stringWriter   = new StringWriter();
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

        irntable.RenderControl(htmlTextWriter);
        StringReader stringReader = new StringReader(stringWriter.ToString());
        Document     Doc          = new Document(PageSize.A6);
        HTMLWorker   htmlparser   = new HTMLWorker(Doc);

        PdfWriter.GetInstance(Doc, Response.OutputStream);
        Doc.Open();
        htmlparser.Parse(stringReader);
        Doc.Close();
        Response.Write(Doc);
        Server.Transfer("~/Events.aspx");
        Response.End();
    }
Esempio n. 16
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            this.Page.RenderControl(hw);
            StringReader sr          = new StringReader(sw.ToString());
            Document     pdfDoc      = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
            string       pdfFileName = Request.PhysicalApplicationPath + "User\\Trans\\GenerateHTMLTOPDF.pdf";
            HTMLWorker   htmlparser  = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
Esempio n. 17
0
        private byte[] GetOptionWithParse(string html)
        {
            StringReader sr = new StringReader(html);

            byte[]     bytes;
            Document   pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
                pdfDoc.Open();

                htmlparser.Parse(sr);
                pdfDoc.Close();

                bytes = memoryStream.ToArray();
                memoryStream.Close();
            }
            return(bytes);
        }
Esempio n. 18
0
    protected void process(object sender, CommandEventArgs e)
    {
        string attachment = "attachment; filename=test.pdf";

        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter   stringWriter = new StringWriter();
        HtmlTextWriter htmlWriter   = new HtmlTextWriter(stringWriter);

        htmlWriter.AddStyleAttribute("font-size", "10pt");
        htmlWriter.AddStyleAttribute("color", "Black");
        testPanel.RenderControl(htmlWriter);
        using (Document document = new Document()) {
            PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            StringReader stringReader = new StringReader(stringWriter.ToString());
            HTMLWorker   htmlworker   = new HTMLWorker(document);
            htmlworker.Parse(stringReader);
        }
        Response.End();
    }
Esempio n. 19
0
        /// <summary>
        /// Создаем PDF-документ из HTML-документа
        /// </summary>
        public void CreatePDFDocument(string fileName, string strHtml, Rectangle rectangle)
        {
            // Добавляем поддержку русских символов
            FontFactory.Register("C:\\WINDOWS\\Fonts\\arial.ttf"); // путь к файлу шрифта
            // Создаем документ
            Document document = new Document();

            //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
            document.SetPageSize(rectangle);
            // Создаем PDF-документ
            PdfWriter.GetInstance(document,
                                  new FileStream(fileName, FileMode.Create));
            StringReader se  = new StringReader(strHtml);
            HTMLWorker   obj = new HTMLWorker(document);

            document.Open();
            // Создаем PDF на основе HTML
            obj.Parse(se);
            // Сохраняем файл
            document.Close();
        }
Esempio n. 20
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            //string htmlText = "<h5>cehars</h5> <h3>arslan</h3>";
            string htmlText = "<h5>cehars</h5>";

            htmlText += "<h3>arslan</h3>";
            Document pdf = new Document();

            PdfWriter.GetInstance(pdf, new FileStream("C:\\Users\\tugdev\\Desktop\\Raporum2.pdf", FileMode.Create));

            pdf.Open();

            HTMLWorker htmlworker = new HTMLWorker(pdf);

            htmlworker.Parse(new StringReader(htmlText));

            pdf.Close();

            Label1.Text    = TextBox1.Text;
            Label1.Visible = true;
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Invoice.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        Panel1.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        //Document pdfDoc = new Document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
        Document   pdfDoc     = new Document(iTextSharp.text.PageSize.A4.Rotate(), 25, 25, 30, 30);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
Esempio n. 22
0
    protected void exportBtn_Click(object sender, EventArgs e)
    {
        try
        {
            int    locationID = int.Parse(locationsList.SelectedValue);
            string month      = MonthsList.SelectedValue;
            string year       = yearList.SelectedValue;

            if (locationsList.SelectedIndex != 0 && yearList.SelectedIndex != 0)
            {
                System.Web.UI.WebControls.GridView reportGrid = new System.Web.UI.WebControls.GridView();
                reportGrid.DataSource = pdfReportData(locationID, month, year);
                reportGrid.DataBind();

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                reportGrid.RenderControl(hw);
                StringReader sr         = new StringReader(sw.ToString());
                Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();
            }
            else
            {
                msg.Text = "Please specify all the required report's details.";
            }
        }
        catch (Exception ex)
        {
            msg.Text = "There was something wrong." + ex.Message;
        }
    }
Esempio n. 23
0
        protected void btnExportPDF_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                // string strPath = "../Client.UI/GetImage.ashx?TrustMID=" + Convert.ToInt32(Session[ApplicationSession.TRUSTID]);

                Response.Clear();
                Response.Buffer          = true;
                Response.ContentType     = "application/pdf";
                Response.ContentEncoding = System.Text.Encoding.Unicode;
                Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
                Response.AddHeader("content-disposition", "attachment;filename=EmployeeList" + "_" + DateTime.Now.Date.ToString("yyyy-MM-dd") + ".pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                gvReport.AllowPaging = false;
                //gvReport.DataBind();
                gvReport.RenderControl(hw);

                // string content = <div style='width:100% ;border-bottom:1px solid Black;'><div style='width:15%; float:left;padding-left:10px'><img src='"+ strPath +"' alt='logo' /></div><div style='width:85%; float:right;font-size:18px; padding-top:10px;'>" + Session[ApplicationSession.TRUSTNAME].ToString() + "</div></div>
                string content = "<div align='center' style='font-family:verdana;font-size:13px'><span style='font-size:16px:font-weight:bold;color:Maroon;'>Report : Employee List</span><br/><span style='font-size:13px:font-weight:bold'></span><br/><span align='center' style='font-family:verdana;font-size:11px'><strong>Date :</strong>" + System.DateTime.Now.ToShortDateString() + "</span><br/><span align='center' style='font-family:verdana;font-size:11px'><strong>Trust Name :</strong>" + Session[ApplicationSession.TRUSTNAME].ToString() + "</span><br/><span align='center' style='font-family:verdana;font-size:11px'><strong>Department :</strong>" + lblDepartmenmt.Text + "</span><br/><div align='center' style='font-family:verdana;font-size:11px'><strong>Designation:</strong>" + lblDesignation.Text + "</span><br/><span align='center' style='font-family:verdana;font-size:11px'><strong>Role:</strong>" + lblRole.Text + "</div><br/><br/>" + sw.ToString() + "<br/>";
                // Response.Output.Write(content);

                StringReader sr         = new StringReader(content);
                Document     pdfDoc     = new Document(PageSize.A3, 10f, 10f, 10f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                // Response.End();
            }
            catch (System.Threading.ThreadAbortException lException)
            {
                // logger.Error("Error", ex);
                ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Oops! There is some technical issue. Please Contact to your administrator.');", true);
            }
        }
        private void GeneratePdf()
        {
            Patient aPatient  = (Patient)ViewState["patient"];
            string  printDate = DateTime.Now.ToString("F");

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + aPatient.MobileNumber + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            ShowTestsGridView.RenderControl(hw);
            ShowTestsGridView.HeaderRow.Style.Add("width", "15%");
            ShowTestsGridView.HeaderRow.Style.Add("font-size", "10px");
            ShowTestsGridView.Style.Add("text-decoration", "none");
            ShowTestsGridView.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
            ShowTestsGridView.Style.Add("font-size", "8px");
            Paragraph paragraph1 = new Paragraph("XXX Diagnostic Center\n\n");

            paragraph1.Font.Size = 30;
            Paragraph    paragraph2 = new Paragraph("Print Date: " + printDate + "\n\n");
            Paragraph    paragraph3 = new Paragraph(" Bill Number: " + aPatient.BillNumber + "\n Invoice Date: " + aPatient.InvoiceDate.ToString("d") + "\n Patient Name: " + aPatient.Name + "\n Date of Birth: " + aPatient.DateOfBirth.ToString("d") + "\n Mobile Number: " + aPatient.MobileNumber + "\n\n");
            Paragraph    paragraph4 = new Paragraph("Total Fee: " + aPatient.Fee + "");
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            pdfDoc.Add(paragraph1);
            pdfDoc.Add(paragraph2);
            pdfDoc.Add(paragraph3);
            htmlparser.Parse(sr);
            pdfDoc.Add(paragraph4);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
            ShowTestsGridView.AllowPaging = true;
            ShowTestsGridView.DataBind();
        }
Esempio n. 25
0
    // Versão Original em: https://social.msdn.microsoft.com/Forums/pt-BR/049133ce-2ce0-4b6e-9194-53b62e12ddbe/como-gerar-um-arquivo-pdf-a-partir-de-uma-pagina-aspx?forum=aspnetpt
    private void ConverteAspx2Pdf()
    {
        // Limpa qualquer coisa já previamente renderizada!
        Response.ClearContent();
        // Para fazer download direto é só descomentar a linha abaixo, caso contrario o PDF é exibido no navegador
        // Response.AddHeader("content-disposition", "attachment; filename=ExportacaoAspx2Pdf.pdf");

        // Altera o tipo de documento
        Response.ContentType = "application/pdf";

        // Prepara um buffer que conterá todo o HTML que é renderizado
        StringWriter   stw    = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);

        // Renderiza todo o HTML do ASPX no buffer (string)
        this.RenderControl(htextw);

        // Cria um novo documento PDF em branco
        Document document = new Document();

        // Define o local de saida (gravação) do PDF como o dispositivo de transmissão do ASP.Net que vai para o navegador
        PdfWriter.GetInstance(document, Response.OutputStream);
        document.Open();

        // Lê o HTML completo do buffer como uma String
        StringReader str = new StringReader(stw.ToString());

        // Chama um conversor interno de HTML para PDF
        HTMLWorker htmlworker = new HTMLWorker(document);

        // Transforma o HTML em PDF
        htmlworker.Parse(str);
        document.Close();

        // Transmite o HTML para o browser
        Response.Write(document);

        // Finaliza tudo!
        Response.End();
    }
Esempio n. 26
0
        public void GeneratePdf()
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Bill.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            StringWriter sw = new StringWriter();

            testEntryGridView.GridLines = GridLines.Both;
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            testEntryGridView.RenderControl(hw);

            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 40f, 40f, 20f, 40f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            string header = "NS Diagnostic Centre";

            pdfDoc.Add(new Paragraph("                                                                   NS Diagnostic Centre        "));
            pdfDoc.Add(new Paragraph("                                                                --------------------------"));
            pdfDoc.Add(new Paragraph("                                                                       Bill Reciept"));

            pdfDoc.Add(new Paragraph("  Date: " + date));
            pdfDoc.Add(new Paragraph("  Bill NO: " + billNo));
            pdfDoc.Add(new Paragraph("  Name: " + Name));
            pdfDoc.Add(new Paragraph("  Code: " + code));
            pdfDoc.Add(new Paragraph("  Mobile No: " + contactNo));
            pdfDoc.Add(new Paragraph("  "));
            htmlparser.Parse(sr);
            pdfDoc.Add(new Paragraph("                                                                                                    Total Amount : " + totalTextBox.Value));

            pdfDoc.Close();
            Response.Write(pdfDoc);

            Response.Flush();
            Response.End();
        }
Esempio n. 27
0
    protected void btnGenPdf_Click(object sender, EventArgs e)
    {
        iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
        styles.LoadStyle("Invoice-Wrp", "width", "1200px");
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=PaymentInvoice.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        this.Page.RenderControl(hw);
        StringReader sr         = new StringReader(sw.ToString());
        Document     pdfDoc     = new Document(PageSize.A4, 50f, 50f, 50f, 50f);
        HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
        private void GeneratePdf(GridView gridView, string filename)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.pdf", filename));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            gridView.AllowPaging = false;
            LoadHostData();
            gridView.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
Esempio n. 29
0
        // generate pdf
        // [Obsolete]
        private void GeneratePDF(string strHTML, string department, string year, string month)
        {
            Document  pdfDoc    = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);

            pdfDoc.Open();

#pragma warning disable CS0612 // Type or member is obsolete
            HTMLWorker htmlWorker = new HTMLWorker(pdfDoc);
#pragma warning restore CS0612 // Type or member is obsolete
            htmlWorker.Parse(new StringReader(strHTML));
            pdfWriter.CloseStream = false;
            pdfDoc.Close();
            Response.Buffer      = true;
            Response.ContentType = "application/pdf";
            string attachment = "attachment;filename=" + department + " " + year.ToString() + "-" + month + ".pdf";
            Response.AddHeader("content-disposition", attachment);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.Flush();
            Response.End();
        }
Esempio n. 30
0
    private void ExportGridToPDF()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Student performence.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView2.RenderControl(hw);
        StringReader sr         = new StringReader(sw.ToString());
        Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
        GridView2.AllowPaging = true;
        GridView2.DataBind();
    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Visible       = false;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=studzer-Acknowledgement.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            this.Page.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
            Server.Transfer("SearchHostel.aspx");
        }