【发布时间】:2015-03-06 06:05:49
【问题描述】:
我正在开发一个 ASP.NET Web 表单应用程序,我必须在其中生成 pdf 并在客户端打印它。我的朋友给了这个代码:
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", a);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
n.RenderControl(hw);
deg.RenderControl(hw);
n.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 70f, 70f, 70f, 70f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.NewPage();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
此代码生成 pdf,但会在客户端自动下载。我不希望它被下载,而是直接打印在客户端。
我不知道如何进一步进行,但我认为 pdf 不应写为“响应”,而应写为内存流并打印为 adobe reader 的后台进程。怎么做?请分享一些代码。
【问题讨论】:
-
看看这个 :) 它可能对你有帮助 :) stackoverflow.com/questions/8294057/…
-
您无法阻止下载文档,因为 PDF 查看器需要磁盘上的文件才能呈现它。见stackoverflow.com/questions/22880444/…
-
您不能“强制打印”下载到客户端的 PDF 文档,因为这被认为存在安全隐患:stackoverflow.com/questions/26751910/…
标签: c# asp.net pdf itextsharp