public static ReportContentResult GeneratePdf(Stream reportDefinitionStream, Action <ReportDataSourceCollection> action, string fileName, object parameters = null) { var reportViewer = new ReportViewer(); reportViewer.LocalReport.LoadReportDefinition(reportDefinitionStream); reportDefinitionStream.Close(); reportViewer.LocalReport.EnableExternalImages = true; if (parameters != null) { reportViewer.LocalReport.SetParameters(parameters.ToReportParamenters()); } action(reportViewer.LocalReport.DataSources); reportViewer.LocalReport.Refresh(); Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtension; string deviceInfo = "<DeviceInfo>" + " <EmbedFonts>None</EmbedFonts>" + "</DeviceInfo>"; byte[] bytes = reportViewer.LocalReport.Render("PDF" /* PDF / EXCEL */, deviceInfo, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); var file = new ReportContentResult(bytes, mimeType); return(file); }
public static ReportContentResult Export(byte[] fileDefinition, DataTable[] dataTableAsDataSources, DataTable parameters = null) { ReportContentResult result = null; using (var memoryStream = new MemoryStream(fileDefinition)) { result = GenerateDataTablePdf(memoryStream, collection => { for (int i = 0; i < dataTableAsDataSources.Length; i++) { collection.Add(new ReportDataSource(dataTableAsDataSources[i].TableName, dataTableAsDataSources[i])); } }, null, parameters); } return(result); }
public static ReportContentResult Export(byte[] fileDefinition, DataSource[] dataSources, string parametersJson = null) { ReportContentResult result = null; using (var memoryStream = new MemoryStream(fileDefinition)) { result = GeneratePdf(memoryStream, collection => { for (int i = 0; i < dataSources.Length; i++) { collection.Add(dataSources[i].CreateReportDataSource(Guid.NewGuid())); } }, null, parametersJson == null ? null : JsonConvert.DeserializeObject(parametersJson, typeof(Dictionary <string, string>))); } return(result); }