【问题标题】:How to export to PDF on the click of view report button of report viewer in vb.net如何在 vb.net 中单击报表查看器的查看报表按钮导出为 PDF
【发布时间】:2014-05-22 11:20:08
【问题描述】:
您能帮我如何将自己的代码添加到报告查看器按钮,以便它将我的数据直接导出到 PDF。
我在其中一个线程中得到了以下答案,想知道如何做到这一点。
您可以创建自己的自定义报告查看控件。该控件将由报告参数字段和生成报告的按钮组成。当用户单击按钮时,您可以在后台生成报告。您可以将报告显示为 PDF。
【问题讨论】:
标签:
vb.net
reporting-services
【解决方案1】:
为了实现你的目标,我认为你有两个选择:
- 直接使用 Report Server Web 服务获取 PDF 文件所需的输出
- 使用 ReportViewer 控件并从中呈现 PDF
如果可以的话,使用reportviewer 控件可能是更容易维护的选项。根据您的要求,您可能需要混合使用这两种方法的元素。
选项 1
请参阅此问题提供的答案,以获得直接访问 Web 服务的不错的入门解决方案
Reporting services: Get the PDF of a generated report
选项 2
将 ReportViewer 控件的输出呈现为 PDF 只需将 Report Viewer 输出呈现为字节数组,然后将其发送到 MemoryStream 对象并写入输出流。下面的示例代码将获取报表查看器控件中当前配置的报表,并直接在当前网页中生成 PDF:
Warning[] warnings = null;
string[] streamids = null;
string mimeType = null;
string encoding = null;
string extension = null;
byte[] bytes = null;
bytes = ReportViewer1.ServerReport.Render("PDF", null, mimeType, encoding, extension, streamids, warnings);
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
Response.ContentType = "Application/pdf";
Response.BinaryWrite(ms.ToArray());
Response.End();