问题描述
亲爱的所有人,
我需要在C#Asp.Net中将网页导出到Pdf。网页包含GridView和MsChart所以我有问题导出pdf任何一个请帮助我。
我使用以下代码导出Pdf但我得到错误路径中的非法破坏者给我解决方案如何解决它。
public void Export()
{
Response.ContentType =application / pdf;
Response.AddHeader(content-disposition,attachment; filename = TestPage.pdf);
回复.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
文件pdfDoc =新文件(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();
}
Dear All,
I Need Export the Web page to Pdf in C# Asp.Net. The Web Page Contains GridView and MsChart so i have a problem to export the pdf any one please help Me.
I am using following Code for Export Pdf but i get Error of illegal chareters in path give me solution for how to solve it.
public void Export()
{
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();
}
推荐答案
这篇关于将网页(包含Mschart和Gridview)导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!