public FileStreamResult PdfView(string viewPath, object model, Phantom phantom) { return File (GetPdf (viewPath, model, phantom), MIME_TYPE_PDF); }
public Stream GetPdf(string viewPath, object model, Phantom phantom) { var rgx = new Regex (@"(src|href)\s?=\s?('|"")/"); string content = rgx.Replace (RenderView (viewPath, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl)); var reportingService = new ReportingService (ReportServerUrl); if (!string.IsNullOrWhiteSpace (phantom.header)) { phantom.header = rgx.Replace (RenderPartialView (phantom.header, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl)); } if (!string.IsNullOrWhiteSpace (phantom.footer)) { phantom.footer = rgx.Replace (RenderPartialView (phantom.footer, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl)); } if (string.IsNullOrWhiteSpace (phantom.format)) { phantom.format = "Letter"; } if (string.IsNullOrWhiteSpace (phantom.margin)) { phantom.margin = "6 mm"; } var report = reportingService.RenderAsync (new RenderRequest { template = new Template { content = content, engine = "none", recipe = "phantom-pdf", phantom = phantom } }).Result; return report.Content; }