“HtmlParser”在当前上下文中不存在

编程入门 行业动态 更新时间:2024-10-26 10:33:05
本文介绍了“HtmlParser”在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当im Build然后生成此错误... 'HtmlParser'在当前上下文中不存在 所以plz给我一些关于这个错误的代码或信息....

解决方案

使用System; 使用System.Collections; 使用System.Configuration; 使用System.Data; 使用System。 Linq; 使用System.Web; 使用System.Web.Security; 使用System.Web.UI; 使用System.Web.UI.HtmlControls; 使用System.Web.UI.WebControls; 使用System.Web.UI.WebControls.WebParts; 使用System.Xml.Linq; 使用System.IO; 使用iTextSharp.text; 使用iTextSharp。 text.pdf; 使用iTextSharp.text.html; protected void Unnamed1_Click(object sender,EventArgs e) { HtmlForm form = new HtmlForm(); form.Controls.Add(GridView1); StringWriter sw = new StringWriter(); HtmlTextWriter hTextWriter = new HtmlTextWriter(sw); form.Controls [0] .RenderControl(hTextWriter); string html = sw.ToString(); Document Doc = new Document(); PdfWriter.GetInstance(Doc,new FileStream(Environment.GetFolderPath (环境) .SpecialFolder.Desktop)+\\abc.pdf,FileMode.Create)); Doc.Open(); Chunk c = new Chunk(使用iTextSharp \ n将GridView导出为PDF,FontFactory.GetFont(Verdana,15)); 段落p = new段落(); p.Alignment = Element.ALIGN_CENTER; p.Add(c); Chunk chunk1 = new Chunk(Example\\\, FontFactory.GetFont(Verdana,8)); 段落p1 =新段落(); p1.Alignment = Element.ALIGN_RIGHT; p1.Add(chunk1); Doc.Add(p); Doc.Add(p1); System.Xml.XmlTextReader xmlReader = 新的System.Xml.XmlTextReader(new StringReader(html)); HtmlParser.Parse(Doc,xmlReader); Doc.Close(); string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+\\ abc.pdf ; ShowPdf(路径); } private void ShowPdf (字符串路径) { Response.ClearContent(); Response.ClearHeaders(); 回复.ContentType =application / pdf; Response.AddHeader(Content-Disposition,附件; filename =+ strS); Response.TransmitFile(strS); Response.End(); //Response.WriteFile( strS); Response.Flush(); Response.Clear(); }

您好 更改此行代码 System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader (new StringReader(html)); HtmlParser.Parse(Doc,xmlReader); 到这一个 HTMLWorker worker = new HTMLWorker(Doc); worker .Parse(new StringReader(html)); Doc.Close(); 确保将iTextSharp.text.html.simpleparser添加为HTMLWorker的名称空间 Chukse

when i m Build then generated this error... " 'HtmlParser' does not exist in the current context " so plz give me some code or information regarding this error....

解决方案

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html; protected void Unnamed1_Click(object sender, EventArgs e) { HtmlForm form = new HtmlForm(); form.Controls.Add(GridView1); StringWriter sw = new StringWriter(); HtmlTextWriter hTextWriter = new HtmlTextWriter(sw); form.Controls[0].RenderControl(hTextWriter); string html = sw.ToString(); Document Doc = new Document(); PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath (Environment.SpecialFolder.Desktop) + "\\abc.pdf", FileMode.Create)); Doc.Open(); Chunk c = new Chunk("Export GridView to PDF Using iTextSharp \n", FontFactory.GetFont("Verdana", 15)); Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_CENTER; p.Add(c); Chunk chunk1 = new Chunk("Example\n", FontFactory.GetFont("Verdana", 8)); Paragraph p1 = new Paragraph(); p1.Alignment = Element.ALIGN_RIGHT; p1.Add(chunk1); Doc.Add(p); Doc.Add(p1); System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(new StringReader(html)); HtmlParser.Parse(Doc, xmlReader); Doc.Close(); string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\abc.pdf"; ShowPdf(Path); } private void ShowPdf(string Path) { Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=" + strS); Response.TransmitFile(strS); Response.End(); //Response.WriteFile(strS); Response.Flush(); Response.Clear(); }

Hi Change this line of code System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(new StringReader(html)); HtmlParser.Parse(Doc, xmlReader); To this one HTMLWorker worker = new HTMLWorker(Doc); worker.Parse(new StringReader(html)); Doc.Close(); Make sure to add iTextSharp.text.html.simpleparser as namespace for HTMLWorker Chukse

更多推荐

“HtmlParser”在当前上下文中不存在

本文发布于:2023-11-09 15:09:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   中不   HtmlParser

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!