• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# simpleparser.HTMLWorker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中iTextSharp.text.html.simpleparser.HTMLWorker的典型用法代码示例。如果您正苦于以下问题:C# HTMLWorker类的具体用法?C# HTMLWorker怎么用?C# HTMLWorker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HTMLWorker类属于iTextSharp.text.html.simpleparser命名空间,在下文中一共展示了HTMLWorker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: DownloadPDF

    protected void DownloadPDF()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        StringWriter sw2 = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        HtmlTextWriter hw2 = new HtmlTextWriter(sw2);
        Report.RenderControl(hw);

        // StringWriter sw2 = new StringWriter();
        // HtmlTextWriter hw2 = new HtmlTextWriter(sw2);
        // NonDisclosureAgreement.RenderControl(hw2);

        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

        NonDisclosureAgreement.RenderControl(hw2);
        string myString = sw.ToString().Trim();

        //string myString3 = NonDisclosureAgreement.InnerHtml;
        string myString3 = sw2.ToString();
        //Header//
        //StringBuilder sb = new StringBuilder();

        //sb.Append(myString);
        //sb.Insert(0, '<div>  <p style='color: #800000; text-align:center'><strong>EXECUTIVE REPORT</strong></p><div><br/><br/>');
        //myString = sb.ToString();
        //Header//

        //////// AS EXAMPLE // ONLY REPLACE THE IMAGES FOR STATIC IMAGES LIKE COUNTRIES://////////////////
        ///  The next 4 lines made it work////
        // string myString2 = Server.MapPath("Advertiser/Ads/").ToString(CultureInfo.InvariantCulture);
        //string myString2 = Server.MapPath("Advertiser/images/").ToString(CultureInfo.InvariantCulture);
        //myString = myString.Replace("Advertiser/Ads/", myString2.ToString());
        //myString3 = myString.Replace("Advertiser/Ads/", myString3.ToString());

        //myString = Strings.Replace(myString, '<th', '<th align='center'');

        ///  The next 4 lines made it work////

        StringReader str = new StringReader(myString);
        StringReader str2 = new StringReader(myString3);
        pdfDoc.Open();

        htmlparser.Parse(str);

        // step 4: we create a table and add it to the document
           // BuyerTable2(pdfDoc);

        pdfDoc.NewPage();
        htmlparser.Parse(str2);

        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
开发者ID:haithemaraissia,项目名称:Advertise,代码行数:59,代码来源:SideJobReportDownload2.aspx.cs


示例17: HtmlToPdf

 public static void HtmlToPdf(string html, string filePath) {
     Document document = new Document();
     PdfWriter.GetInstance(document, new FileStream(filePath, FileMode.Create));
     document.Open();
     //Image pdfImage = Image.GetInstance(Server.MapPath("logo.png"));
     //pdfImage.ScaleToFit(100, 50);
     //pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760);
     //document.Add(pdfImage);
     iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
     iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
     hw.Parse(new StringReader(html));
     document.Close();
 }
开发者ID:gopalcb,项目名称:PDF_Generator_Demo,代码行数:13,代码来源:Program.cs


示例18: GeneratePDFAndMail

    private void GeneratePDFAndMail()
    {
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        if (Guarantee.Checked)
        {
            tblGuarantee.RenderControl(hw);
        }
        if (chkNominee.Checked)
        {
            tblNominee.RenderControl(hw);
        }

        StringReader sr = new StringReader(sw.ToString());
        var pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        MemoryStream memoryStream = new MemoryStream();
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
        pdfDoc.Open();

        iTextSharp.text.Image logoHeader = iTextSharp.text.Image.GetInstance(@"PDF.jpg");
        logoHeader.ScaleAbsolute(500, 300);
        pdfDoc.Add(logoHeader);

        htmlparser.Parse(sr);
        writer.CloseStream = false; //set the closestream property
        pdfDoc.Close(); //close the document without closing the underlying stream
        memoryStream.Position = 0;

           MailAddress to = new MailAddress (txtemail.Text);
        MailAddress from = new MailAddress (ConfigurationManager.AppSettings ["smtpUser"]);

        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to);
        mail.Attachments.Add(new Attachment(memoryStream, to + DateTime.Now.ToString("MMM-dd HH:mm") + ".pdf"));
        mail.Subject = "Test Mail";
        mail.Body = "Hi hafi here";
        SmtpClient client = new SmtpClient();
        var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
        client.Credentials = new System.Net.NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password);
        client.Port = smtpSection.Network.Port;
        client.Host = smtpSection.Network.Host;
        client.EnableSsl = true;
        try
        {
            client.Send(mail);
        }
        catch (Exception ex)
        {
        }
    }
开发者ID:hafizor,项目名称:stgeorge,代码行数:51,代码来源:Default.aspx.cs


示例19: PrintPDF

        public void PrintPDF()
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=AdvertiserReport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            var sw = new StringWriter();
            var sw2 = new StringWriter();
            var hw = new HtmlTextWriter(sw);
            var hw2 = new HtmlTextWriter(sw2);

            gvdetails.DataBind();
            gvdetails.RenderControl(hw);
            SumTable.RenderControl(hw2);

            var pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
            var htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

            var gridString = sw.ToString();
            var sumTableString = sw2.ToString();

            //Header//
            var sb = new StringBuilder("<div><p style='color: #800000; text-align:center'><strong>");
            sb.Append(Resources.Resource.AdvertiserReport);
            sb.Append("</strong></p></div><br/>");
            sb.Append(sumTableString);
            sumTableString = sb.ToString();
            //Header//

            //Images//
            var gridString2 = Server.MapPath("../Advertiser/Ads/").ToString(CultureInfo.InvariantCulture);
            gridString = gridString.Replace("../Advertiser/Ads/", gridString2);
            //Images//

            var gridStringReader = new StringReader(gridString);
            var sumStringReader = new StringReader(sumTableString);

            pdfDoc.Open();
            htmlparser.Parse(sumStringReader);
            htmlparser.Parse(gridStringReader);

            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
开发者ID:haithemaraissia,项目名称:Advertise,代码行数:46,代码来源:AdvertiserDownload.aspx.cs


示例20: RenderFromHtml

        public byte[] RenderFromHtml(string html)
        {
            var output = new MemoryStream ();
            using (var reader = new StringReader (html)) {
                var document = new Document ();
                var worker = new HTMLWorker (document);

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

                worker.EndDocument ();
                worker.Close ();
                document.Close ();

                return output.ToArray ();
            }
        }
开发者ID:AlexCuse,项目名称:RazorReport,代码行数:18,代码来源:PdfRenderer.cs



注:本文中的iTextSharp.text.html.simpleparser.HTMLWorker类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# pdf.BaseFont类代码示例发布时间:2022-05-26
下一篇:
C# text.Table类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap