本文介绍了我在我的代码中收到错误,从asp.net页面生成pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  Submitbtn_Click(对象发​​件人,EventArgs e)
{
{Response.ContentType = 应用/ PDF;
Response.AddHeader( content-disposition attachment; filename = FileName.pdf);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter w = new HtmlTextWriter(sw);
print.RenderControl(w)

string htmWrite = sw.GetStringBuilder()。ToString();
htmWrite = Regex.Replace(htmWrite, );
htmWrite = htmWrite.Replace( \\\\ n );
StringReader reader = new StringReader(htmWrite);

文件doc = new 文件(PageSize.A4,10f,10f,100f,0f);
string pdfFilePath = Server.MapPath( )+ / PDFFiles;

HTMLWorker htmlparser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc,Response.OutputStream);

doc.Open();
尝试
{

htmlparser.Parse(读者);
doc.Close();
Response.Write(doc);
Response.End();
}
catch (例外)
{}
最后
{
doc.Close();
}



public 覆盖 void VerifyRenderingInServerForm(控制控件)
{
/ * 验证控件是否已呈现* /
}
}
显示错误
RegisterForEventValidation只能在Render()期间调用;
解决方案


这篇关于我在我的代码中收到错误,从asp.net页面生成pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 10:34