我需要在 ASP.Net 网页(使用 C# 服务器端脚本)中显示报表的预览。预览需要是 PDF 而不是 HTML 并内联显示(可能在 iframe 中?)。
是否可以指定呈现为 PDF 的报告的标题,以便其“Content-Disposition”是内联的而不是附件?
或者是否有任何其他方法可以在 ASP.Net 网页中显示呈现为内联 PDF 的报告?
我正在使用 Reporting Services 2008
在 ASP.Net 站点中,我使用了对 ReportService2005.asmx 和 ReportExecution2005.asmx 的 Web 引用
最佳答案
我正在做一些非常相似的事情。但我使用的是 HttpWebRequest 而不是使用该服务。这就是我的做法。 重要的部分是 Content-Disposition 中文件名之前的内联。
这还取决于他们的 Adobe Reader 版本(我们发现他们需要 7 或更高版本)以及他们在其中设置的设置(以防他们将其设置为不在浏览器中打开 PDF)。
HttpResponse currentResponse = HttpContext.Current.Response;
currentResponse.Clear();
currentResponse.ClearHeaders();
currentResponse.ClearContent();
filename = String.Format("{0}.pdf", this.ReportName);
currentResponse.AppendHeader("Content-Disposition", String.Format("inline;filename={0}", filename));
currentResponse.ContentType = "Application/PDF";
//Copy the content of the response to the
//current response using BinaryWrite
snip....
currentResponse.End();
关于c# - 如何在 ASP.Net 和 C# 网页中将 Reporting Services 报告显示为内联 PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/584609/