我有一个.aspx页面,其中有一个面板,一些控件和一个gridview。我正在尝试打印该面板,但下载的pdf为空。我不知道为什么,有人可以解释一下吗?
这是我正在尝试的代码
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.pnlprint.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();
答案 0 :(得分:0)
尝试更改您的:
Response.Write(pdfDoc);
为:
Response.BinaryWrite(pdfDoc.ToArray());