reportviewer导出为pdf文件
reportviewer控件本身有导出功能,但不灵活,当遇到特殊需求是需要我们自己写代码来导出,比如批次导出
第9行中如果用得是服务器报表,报表的ProcessingMode=ProcessingMode.Remote,则使用ReportViewer.ServerReport.Render方法
如果ProcessingMode=ProcessingMode.Local,则使用ReportViewer.LocalReport.Render方法
1 private void ConvertToPdf(string strFileName)
2 {
3 Warning[] warnings;
4 string[] streamids;
5 string mimeType;
6 string encoding;
7 string extension;
8
9 byte[] bytes = ReportViewer1.ServerReport.Render(
10 "pdf", null, out mimeType, out encoding,
11 out extension,
12 out streamids, out warnings);
13
14 FileStream fs = new FileStream(@"C:\Users\zhu\" + strFileName + ".pdf",
15 FileMode.Create);
16 fs.Write(bytes, 0, bytes.Length);
17 fs.Close();
18 }
2 {
3 Warning[] warnings;
4 string[] streamids;
5 string mimeType;
6 string encoding;
7 string extension;
8
9 byte[] bytes = ReportViewer1.ServerReport.Render(
10 "pdf", null, out mimeType, out encoding,
11 out extension,
12 out streamids, out warnings);
13
14 FileStream fs = new FileStream(@"C:\Users\zhu\" + strFileName + ".pdf",
15 FileMode.Create);
16 fs.Write(bytes, 0, bytes.Length);
17 fs.Close();
18 }
第9行中如果用得是服务器报表,报表的ProcessingMode=ProcessingMode.Remote,则使用ReportViewer.ServerReport.Render方法
如果ProcessingMode=ProcessingMode.Local,则使用ReportViewer.LocalReport.Render方法