Itextsharp导出为pdf NullReferenceException [英] Itextsharp export to pdf NullReferenceException
本文介绍了Itextsharp导出为pdf NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将aspx页面导出为pdf。我在Button2_Click上使用此代码,但我在htmlworker.Parse(str)上采用System.NullReferenceException;:
I am trying to export the aspx page to pdf. I am using this code on Button2_Click, but i take a System.NullReferenceException on htmlworker.Parse(str);:
string attachment = "attachment; filename=Article.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
dvText.RenderControl(htextw);
Document document = new Document();
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
document.Close();
Response.Write(document);
Response.End();
推荐答案
您的HTML是否包含< ; hr>
标签? HTMLworker不支持它。
Does your HTML contain <hr>
tag? It's not supported in HTMLworker.
这篇关于Itextsharp导出为pdf NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文