Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我需要良好的ITextSharp ASPX到PDF转换的例子_Asp.net_Pdf_Itextsharp_.net - Fatal编程技术网

Asp.net 我需要良好的ITextSharp ASPX到PDF转换的例子

Asp.net 我需要良好的ITextSharp ASPX到PDF转换的例子,asp.net,pdf,itextsharp,.net,Asp.net,Pdf,Itextsharp,.net,我有几个aspxweb表单,它们有许多文本框、单选按钮列表、组合框和许多其他奇特的Telerik控件。填写页面并单击提交按钮后,整个页面需要转换为PDF。我需要的例子,我可以如何做到这一点与iTextSharp。我一直在瞎搞一个测试项目,看看它是如何工作的,当我添加一个RadTextBox和一个RadComboBox时,出现了以下异常: 无法将类型为“iTextSharp.text.html.simpleparser.CellWrapper”的对象强制转换为类型为“iTextSharp.text

我有几个aspxweb表单,它们有许多文本框、单选按钮列表、组合框和许多其他奇特的Telerik控件。填写页面并单击提交按钮后,整个页面需要转换为PDF。我需要的例子,我可以如何做到这一点与iTextSharp。我一直在瞎搞一个测试项目,看看它是如何工作的,当我添加一个RadTextBox和一个RadComboBox时,出现了以下异常:

无法将类型为“iTextSharp.text.html.simpleparser.CellWrapper”的对象强制转换为类型为“iTextSharp.text.paragration”。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.InvalidCastException:无法将类型为“iTextSharp.text.html.simpleparser.CellWrapper”的对象强制转换为类型为“iTextSharp.text.paragration”

源错误:

Line 33:             PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
Line 34:             pdfDoc.Open();
Line 35:             htmlparser.Parse(sr);
Line 36:             pdfDoc.Close();
Line 37:             Response.Write(pdfDoc);
堆栈跟踪:

[InvalidCastException:无法将类型为'iTextSharp.text.html.simpleparser.CellWrapper'的对象强制转换为类型为'iTextSharp.text.paragration'

iTextSharp.text.html.simpleparser.HTMLWorker.ProcessLink() +563
iTextSharp.text.html.simpleparser.HTMLTagProcessor_A.EndElement(HTMLWorker worker, String tag) +36
iTextSharp.text.html.simpleparser.HTMLWorker.EndElement(String tag) +80
iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(Boolean start) +136
iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) +1950
iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc, ISimpleXMLDocHandlerComment comment, TextReader r, Boolean html) +83
iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader) +59
WebApplication5._Default.btnExport_Click(Object sender, EventArgs e) in C:\Users\jensenty\Documents\Visual Studio 2008\Projects\WebApplication5\WebApplication5\Default.aspx.cs:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
PDF转换的C#方法:

protected void btnExport_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.Page.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();
}

如能解决这一例外情况,将不胜感激。一般来说,我认为我需要更好地了解如何将iTextSharp用于布满控件的web表单。

我认为如果您的代码工作正常,那么iTextSharp.dll版本只会产生一个问题

你应该浏览这个链接并下载它的版本。然后在任何代码正常运行之后