C# 无法将“iTextSharp.text.html.simpleparser.CellWrapper”类型的对象转换为“iTextSharp.text.Paragraph”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9477288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'
提问by prian prian
While converting GridViewdata to PDFi am getting this error. Please help me. My codes are below.
在将GridView数据转换为PDF我时出现此错误。请帮我。我的代码如下。
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
gv.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gv);
frm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 30f, 30f, 30f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
回答by Jake
回答by Héctor Mejía
I was in a similar situation while I was trying to convert a panel into PDF. The problem was that the panel had a link button, and it seems that this method Parse() just doesn't work fine with link buttons.
我在尝试将面板转换为 PDF 时遇到了类似的情况。问题是面板有一个链接按钮,而且这个方法 Parse() 似乎不适用于链接按钮。
My solution was to make the link button invisible before the conversion and make it visible again after the conversion.
我的解决方案是在转换前使链接按钮不可见,并在转换后使其再次可见。
It is possible that your page contains a link button or any other controls not compatible with Parse().
您的页面可能包含链接按钮或任何其他与 Parse() 不兼容的控件。
回答by Vahid
If you have GridView in the form and its "AllowSorting" property is true, you should false that programatically befor parseand after that change it to true if you need.
如果表单中有 GridView 并且其“ AllowSorting”属性为真,则应该在解析之前以编程方式将其设为假,然后根据需要将其更改为真。
回答by ketan italiya
i think if your code is work perfectly then only one problem create with version of itextsharp.dll,
我认为如果您的代码运行良好,那么 itextsharp.dll 版本只会产生一个问题,
you should vist this link and download version give in it..then after any code working perfectly,
你应该访问这个链接并下载版本给它..然后在任何代码完美运行之后,
回答by user3657080
Your html needs to be perfect or you will receive an exception. So if you are missing a closing tag an exception is thrown
您的 html 需要完美,否则您将收到异常。因此,如果您缺少结束标记,则会引发异常

