本文介绍了错误文档没有页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 using(StringWriter sw = new StringWriter()) { using(HtmlTextWriter hw = new HtmlTextWriter(sw)) { GridView1.AllowPaging = false; this.DataBind(); GridView1.RenderControl(hw) ; StringReader sr = new StringReader(sw.ToString()); 文件pdfdoc =新文件(PageSize.A4,10f, 10f,10f,0f); HTMLWorker htmlparser = new HTMLWorker(pdfdoc); pdfdoc.PageCount = 1; PdfWriter.GetInstance( pdfdoc,Response.OutputStream); pdfdoc.Open(); htmlparser.Parse(sr); pdfdoc.Close(); Response.ContentType =Application / pdf; Response.AddHeader(content-disposition,attachemnt; filename = FileName.pdf); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfdoc); Response.End(); } } 解决方案 您没有在文档中添加新页面 pdfdoc.newPage(); using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { GridView1.AllowPaging = false; this.DataBind(); GridView1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfdoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfdoc); pdfdoc.PageCount = 1; PdfWriter.GetInstance(pdfdoc, Response.OutputStream); pdfdoc.Open(); htmlparser.Parse(sr); pdfdoc.Close(); Response.ContentType = "Application/pdf"; Response.AddHeader("content-disposition", "attachemnt;filename=FileName.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfdoc); Response.End(); } } 解决方案 Hi,You did not add a new Page to the document pdfdoc.newPage(); 这篇关于错误文档没有页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 13:49