public HttpResponseMessage RelQtdeProcedimentosRealizados(DateTime datainicio, DateTime datatermino) { try { if (datainicio > datatermino) { throw new Exception("Periodo inválido"); } var lista = _serviceRelatorio.ProcedimentosRealizados(datainicio, datatermino, base.GetUsuarioLogado().IdClinica); //vinculando dataset ao objeto relat var ds = new ReportDataSource(); ds.Name = "dsdados"; ds.Value = lista; var report = new LocalReport() { ReportPath = AppDomain.CurrentDomain.BaseDirectory + "Report/RelQtdeProcedimentosRealizados.rdlc" }; report.DataSources.Add(ds); report.Refresh(); ReportParameter[] parametros = new ReportParameter[] { new ReportParameter("usuario", base.GetUsuarioLogado().Nome), new ReportParameter("datainicio", datainicio.ToString("dd/MM/yyyy")), new ReportParameter("datatermino", datatermino.ToString("dd/MM/yyyy")) }; report.SetParameters(parametros); //configurações da página ex: margin, top, left ... string deviceInfo = "<DeviceInfo>" + "<OutputFormat>PDF</OutputFormat>" + "<PageWidth>20cm</PageWidth>" + "<PageHeight>29,7cm</PageHeight>" + "<MarginTop>0.5cm</MarginTop>" + "<MarginLeft>0.5cm</MarginLeft>" + "<MarginRight>0.5cm</MarginRight>" + "<MarginBottom>0.5cm</MarginBottom>" + "</DeviceInfo>"; string mimeType = ""; string encoding = ""; string filenameExtension = ""; string[] streams = null; Microsoft.Reporting.WebForms.Warning[] warnings = null; byte[] bytes = report.Render("PDF", deviceInfo, out mimeType, out encoding, out filenameExtension, out streams, out warnings); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new ByteArrayContent(bytes); result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mimeType); return(result); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }