當前位置: 首頁>>代碼示例>>C#>>正文


C# simpleparser.HTMLWorker類代碼示例

本文整理匯總了C#中iTextSharp.text.html.simpleparser.HTMLWorker的典型用法代碼示例。如果您正苦於以下問題:C# HTMLWorker類的具體用法?C# HTMLWorker怎麽用?C# HTMLWorker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HTMLWorker類屬於iTextSharp.text.html.simpleparser命名空間,在下文中一共展示了HTMLWorker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetPDF

        public 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, 10, 10, 10, 5); //era tudo 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);

            // 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;
        }
開發者ID:andresombra,項目名稱:ged,代碼行數:32,代碼來源:GeraPDF.cs

示例2: createPDF

        private MemoryStream createPDF(string html)
        {
            MemoryStream msOutput = new MemoryStream();
            TextReader reader = new StringReader(html);

            // step 1: creation of a document-object
            Document document = new Document(PageSize.A4, 30, 30, 30, 30);

            // step 2:
            // we create a writer that listens to the document
            // and directs a XML-stream to a file
            PdfWriter writer = PdfWriter.GetInstance(document, msOutput);

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

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

            // step 5: parse the html into the document
            worker.Parse(reader);

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

            return msOutput;
        }
開發者ID:Nsobi,項目名稱:PoliceReports,代碼行數:30,代碼來源:PDFUtility.cs

示例3: RenderHtmlToPdfStream

        public static MemoryStream RenderHtmlToPdfStream(string html)
        {
            var memoryStream = new MemoryStream();

            var reader = new StringReader(html);

            using (var document = new Document(PageSize.A4, 30, 30, 30, 30))
            {
                using (var worker = new HTMLWorker(document))
                {
                    using (var writer = PdfWriter.GetInstance(document, memoryStream))
                    {
                        writer.CloseStream = false;

                        document.Open();
                        worker.StartDocument();

                        worker.Parse(reader);

                        worker.EndDocument();
                        worker.Close();
                        document.Close();
                    }
                }
            }
            memoryStream.Seek(0, 0);
            return memoryStream;
        }
開發者ID:n-hogan,項目名稱:master,代碼行數:28,代碼來源:PdfRenderer.cs

示例4: ExportToPDF

        private void ExportToPDF()
        {
            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    //To Export all pages
                    this.gvExportToPdf.AllowPaging = false;
                    //this.BindGridView();

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

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=DashboardReport.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();
                }
            }
        }
開發者ID:raselahmmedgit,項目名稱:kendoui-sample-javascript,代碼行數:27,代碼來源:ExportToPdf.aspx.cs

示例5: btnPDF_Click

 protected void btnPDF_Click(object sender, ImageClickEventArgs e)
 {
     Response.ContentType = "application/pdf";
     Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     var sw = new StringWriter();
     var hw = new HtmlTextWriter(sw);
     gvdetails.AllowPaging = false;
     gvdetails.DataBind();
     gvdetails.RenderControl(hw);
     gvdetails.HeaderRow.Style.Add("width", "15%");
     gvdetails.HeaderRow.Style.Add("font-size", "10px");
     gvdetails.Style.Add("text-decoration", "none");
     gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
     gvdetails.Style.Add("font-size", "8px");
     var sr = new StringReader(sw.ToString());
     var pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
     var htmlparser = new HTMLWorker(pdfDoc);
     PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
     pdfDoc.Open();
     htmlparser.Parse(sr);
     pdfDoc.Close();
     Response.Write(pdfDoc);
     Response.End();
 }
開發者ID:haithemaraissia,項目名稱:Advertise,代碼行數:25,代碼來源:Performance.aspx.cs

示例6: ExportToPDF

        protected void ExportToPDF(DataTable dt)
        {
            GridView gvExport = new GridView();
            gvExport.AllowPaging = false;
            gvExport.DataSource = dt;
            gvExport.DataBind();

            gvExport.HeaderRow.Style.Add("font-size", "10px");
            gvExport.HeaderRow.Style.Add("font-weight", "bold");
            gvExport.Style.Add("text-decoration", "none");
            gvExport.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
            gvExport.Style.Add("font-size", "8px");

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

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

            gvExport.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();
        }
開發者ID:WebKredApp,項目名稱:MyWebKred,代碼行數:33,代碼來源:LinkSpaceCRUDController.aspx.cs

示例7: SaveToPdf_Click1

 protected void SaveToPdf_Click1(object sender, EventArgs e)
 {
     Response.ContentType = "application/pdf";
     Response.AddHeader("content-disposition", "attachment;filename=YourSchedule.pdf");
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     GridView1.HeaderRow.Style.Add("width", "0");
     GridView1.HeaderRow.Style.Add("font-size", "5px");
     GridView1.Style.Add("text-decoration", "none");
     GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
     GridView1.Style.Add("font-size", "5px");
     StringWriter sw = new StringWriter();
     HtmlTextWriter hw = new HtmlTextWriter(sw);
     GridView1.AllowPaging = false;
     GridView1.DataBind();
     GridView1.RenderControl(hw);
     StringReader sr = new StringReader(sw.ToString());
     Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 17f, 10f);
     HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
     PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
     pdfDoc.Open();
     htmlparser.Parse(sr);
     pdfDoc.Close();
     Response.Write(pdfDoc);
     Response.End();
 }
開發者ID:KrzysztofTSuchecki,項目名稱:Schedule,代碼行數:25,代碼來源:SearchSchedule.aspx.cs

示例8: RenderStream

        private static byte[] RenderStream(string htmlText, string pageTitle)
        {
            byte[] renderedBuffer;

            //string filePath = HostingEnvironment.MapPath("~/Content/Pdf/");
            //FileStream fs = new FileStream(filePath + "\\pdf-" + "Test.pdf", FileMode.Create);

            using (var outputMemoryStream = new MemoryStream())
            {
                using (var pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin))
                {
                    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))
                        {
                            htmlWorker.Parse(htmlViewReader);
                        }
                    }
                }

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

            return renderedBuffer;
        }
開發者ID:watcharayarnu,項目名稱:MvcPdfReport,代碼行數:31,代碼來源:StandardPdfRenderer.cs

示例9: PDF

    private void PDF()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);
        divPDF.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();

        //String basePath = Request.ApplicationPath;
        //HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
        //// Load HTML file
        //Document doc = new Document(Request.ApplicationPath + @"\HtmlPage.html", htmloptions);
        //// Save HTML file
        //doc.Save(Request.ApplicationPath + @"\Output.pdf");
    }
開發者ID:rajusreenivasan,項目名稱:VerizonHackathon,代碼行數:26,代碼來源:Default.aspx.cs

示例10: SendPDFEmail

        public void SendPDFEmail(string dt, string Email)
        {
            using (StringWriter sw = new StringWriter())
            {

                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    StringReader sr = new StringReader(dt.ToString());

                    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();
                        byte[] bytes = memoryStream.ToArray();
                        memoryStream.Close();

                        using (MemoryStream inputData = new MemoryStream(bytes))
                        {
                            using (MemoryStream outputData = new MemoryStream())
                            {
                                string PDFFileword = "adt";//you can also generate Dynamic word
                                PdfReader reader = new PdfReader(inputData);
                                PdfEncryptor.Encrypt(reader, outputData, true, "123", "adt", PdfWriter.ALLOW_SCREENREADERS);
                                bytes = outputData.ToArray();
                                try
                                {
                                    MailMessage message = new MailMessage();
                                    SmtpClient smtp = new SmtpClient();

                                    message.From = new MailAddress("[email protected]");
                                    message.To.Add(new MailAddress(Email));
                                    message.Subject = "Test1";
                                    message.Body = "Content test";
                                    message.Attachments.Add(new Attachment(new MemoryStream(bytes), "iTextSharpPDF.pdf"));
                                    smtp.Port = 80;
                                    smtp.Host = "smtpout.secureserver.net";
                                    smtp.EnableSsl = false;
                                    smtp.UseDefaultCredentials = false;
                                    smtp.Credentials = new NetworkCredential("[email protected]", "123456aA");
                                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                                    smtp.Send(message);
                                    label1.Text = "Mail sent successfully";
                                }
                                catch (Exception ex)
                                {
                                    label1.Text = "err: " + ex.Message;

                                }
                            }
                        }
                    }
                }
            }
        }
開發者ID:cvinjamuri,項目名稱:AutopaySlip,代碼行數:60,代碼來源:Payslip.cs

示例11: CreatePDF

        public bool CreatePDF(string text, string outPutPath)
        {
            var returnValue = false;
            try
            {
                StringReader sr = new StringReader(text);

              //  Document pdfDoc = new Document(PageSize.LETTER, 30, 30, 40, 30);
                Document pdfDoc = new Document(PageSize.A4, 30, 30, 40, 30);

                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                //PdfWriter.GetInstance(pdfDoc, new FileStream(@"d:\Temp\Test.pdf", FileMode.Create));

                PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream(outPutPath, FileMode.Create));
                //pdfWriter.PageEvent = new ITextEvents();

                pdfDoc.Open();

                htmlparser.Parse(sr);
                pdfDoc.Close();
                sr.Close();
                returnValue = true;
            }
            catch { }

            return returnValue;
        }
開發者ID:rayanc,項目名稱:Pecuniaus,代碼行數:27,代碼來源:PdfHelper.cs

示例12: Render

        public byte[] Render(string htmlText, string pageTitle)
        {
            byte[] renderedBuffer;

            using (var outputMemoryStream = new MemoryStream())
            {
                using (var pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin))
                {
                    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))
                        {
                            htmlWorker.Parse(htmlViewReader);
                        }
                    }
                }

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

            return renderedBuffer;
        }
開發者ID:spsinghdocument,項目名稱:MVC3SG,代碼行數:28,代碼來源:StandardPdfRenderer.cs

示例13: generatePDFButton_Click

        protected void generatePDFButton_Click(object sender, EventArgs e)
        {
            DataTable aDataTable = aPatientManager.GetData(Convert.ToInt64(voterIdTextBox.Text));

            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.ShowHeaderWhenEmpty = true;
            GridView1.DataSource = aDataTable;
            GridView1.DataBind();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=AllHistoryOfAPatient.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter aStringWriter = new StringWriter();
            HtmlTextWriter aHtmlTextWriter = new HtmlTextWriter(aStringWriter);
            GridView1.RenderControl(aHtmlTextWriter);
            StringReader aStringReader = new StringReader(aStringWriter.ToString());
            Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker aHtmlWorker = new HTMLWorker(pdfDocument);
            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            pdfDocument.Open();
            aHtmlWorker.Parse(aStringReader);
            pdfDocument.Close();
            Response.Write(pdfDocument);
            Response.End();
        }
開發者ID:MirajHossain,項目名稱:Community-Medicine-System,代碼行數:26,代碼來源:PatientHistoryUI.aspx.cs

示例14: btnExport_Click

    protected void btnExport_Click(object sender, EventArgs e)
    {
        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                //To Export all pages
                grid_monthly_attendanceDetailed.AllowPaging = false;
                //this.BindGrid();

                grid_monthly_attendanceDetailed.RenderBeginTag(hw);
                grid_monthly_attendanceDetailed.HeaderRow.RenderControl(hw);
                foreach (GridViewRow row in grid_monthly_attendanceDetailed.Rows)
                {
                    row.RenderControl(hw);
                }
                grid_monthly_attendanceDetailed.FooterRow.RenderControl(hw);
                grid_monthly_attendanceDetailed.RenderEndTag(hw);
                StringReader sr = new StringReader(sw.ToString());
                Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=Report.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Write(pdfDoc);
                Response.End();
            }
        }
    }
開發者ID:hmandal,項目名稱:BiometricsAttendanceSystem,代碼行數:34,代碼來源:MonthlyAttendanceEmployeeWise.aspx.cs

示例15: ASPXToPDF

        public void ASPXToPDF(HtmlTable objhtml1,  HtmlTable objhtml2)
        {
            string fileName = "AsignacionFolios.pdf";
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.Clear();

            StringWriter sw1 = new StringWriter();
            HtmlTextWriter hw1 = new HtmlTextWriter(sw1);
            objhtml1.RenderControl(hw1);

            StringWriter sw2 = new StringWriter();
            HtmlTextWriter hw2 = new HtmlTextWriter(sw2);
            objhtml2.RenderControl(hw2);

            StringReader sr1 = new StringReader(sw1.ToString());
            StringReader sr2 = new StringReader(sw2.ToString());

            Document pdfDoc = new Document(PageSize.A2, 5f, 5f, 5f, 5f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr1);
            pdfDoc.NewPage();

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

            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Write(pdfDoc);
            HttpContext.Current.Response.End();
        }
開發者ID:FranciscoMontelongo,項目名稱:Basica-Prom-Supervisores-Asigna15,代碼行數:33,代碼來源:PDFExpress.cs


注:本文中的iTextSharp.text.html.simpleparser.HTMLWorker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。