“HtmlParser”在当前上下文中不存在 [英] 'HtmlParser' does not exist in the current context
本文介绍了“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”在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文