1

我有一个.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();
4

1 回答 1

0

尝试更改您的:

Response.Write(pdfDoc);

至:

Response.BinaryWrite(pdfDoc.ToArray());
于 2013-05-10T13:48:12.887 回答