private byte[] RenderAsPdf(IReport report, string key, string opt) { var externalUrl = Config.Get <EnvironmentSettings>().SiteExternalUrl ?? Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/"); var renderUrl = UriHelper.Combine(externalUrl, "Report/Render?" + "key=" + Uri.EscapeDataString(key)); if (!string.IsNullOrEmpty(opt)) { renderUrl += "&opt=" + Uri.EscapeDataString(opt); } renderUrl += "&print=1"; var converter = new HtmlToPdfConverter(); converter.Url = renderUrl; var formsCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (formsCookie != null) { converter.Cookies[FormsAuthentication.FormsCookieName] = formsCookie.Value; } var icustomize = report as ICustomizeHtmlToPdf; if (icustomize != null) { icustomize.Customize(converter); } return(converter.Execute()); }
private byte[] RenderAsPdf(IReport report, string key, string opt) { var externalUrl = Config.Get<EnvironmentSettings>().SiteExternalUrl ?? Request.GetBaseUri().ToString(); var renderUrl = UriHelper.Combine(externalUrl, "Report/Render?" + "key=" + Uri.EscapeDataString(key)); if (!string.IsNullOrEmpty(opt)) renderUrl += "&opt=" + Uri.EscapeDataString(opt); renderUrl += "&print=1"; var converter = new HtmlToPdfConverter(); var wkhtmlPath = HostingEnvironment.MapPath("~/bin/wkhtmltopdf.exe"); if (System.IO.File.Exists(wkhtmlPath)) converter.UtilityExePath = wkhtmlPath; converter.Url = renderUrl; var formsCookieName = ".AspNetAuth"; var formsCookie = Request.Cookies[formsCookieName]; if (formsCookie != null) converter.Cookies[formsCookieName] = formsCookie; var icustomize = report as ICustomizeHtmlToPdf; if (icustomize != null) icustomize.Customize(converter); return converter.Execute(); }
private byte[] RenderAsPdf(IReport report, string key, string opt) { var externalUrl = EnvironmentSettings?.SiteExternalUrl ?? Request.GetBaseUri().ToString(); var renderUrl = UriHelper.Combine(externalUrl, "Serenity.Extensions/Report/Render?" + "key=" + Uri.EscapeDataString(key)); if (!string.IsNullOrEmpty(opt)) { renderUrl += "&opt=" + Uri.EscapeDataString(opt); } renderUrl += "&print=1"; var converter = new HtmlToPdfConverter(); var wkhtmlPath = GetWKHtmlToPdfPath(HostEnvironment?.ContentRootPath); if (!string.IsNullOrEmpty(wkhtmlPath)) { converter.UtilityExePath = wkhtmlPath; } else { throw new ValidationError("Can't locate wkhtmltopdf.exe (or wkhtmltopdf in Linux) " + "that is required for report generation in PATH or folder " + System.IO.Path.GetDirectoryName(typeof(ReportController).Assembly.Location) + ". Please download and install the version suitable for your system from " + "https://wkhtmltopdf.org/downloads.html"); } converter.Url = renderUrl; var formsCookieName = ".AspNetAuth"; var formsCookie = Request.Cookies[formsCookieName]; if (formsCookie != null) { converter.Cookies[formsCookieName] = formsCookie; } var languageCookieName = "LanguagePreference"; var languageCookie = Request.Cookies[languageCookieName]; if (languageCookie != null) { converter.Cookies[languageCookieName] = languageCookie; } if (report is ICustomizeHtmlToPdf icustomize) { icustomize.Customize(converter); } return(converter.Execute()); }
private byte[] RenderAsPdf(IReport report, string key, string opt) { var externalUrl = EnvironmentSettings?.SiteExternalUrl ?? Request.GetBaseUri().ToString(); var renderUrl = UriHelper.Combine(externalUrl, "Report/Render?" + "key=" + Uri.EscapeDataString(key)); if (!string.IsNullOrEmpty(opt)) { renderUrl += "&opt=" + Uri.EscapeDataString(opt); } renderUrl += "&print=1"; var converter = new HtmlToPdfConverter(); var wkhtmlPath = System.IO.Path.Combine(typeof(ReportController).Assembly.Location, "wkhtmltopdf.exe"); if (!System.IO.File.Exists(wkhtmlPath)) // linux? { wkhtmlPath = System.IO.Path.Combine(typeof(ReportController).Assembly.Location, "wkhtmltopdf"); } if (System.IO.File.Exists(wkhtmlPath)) { converter.UtilityExePath = wkhtmlPath; } converter.Url = renderUrl; var formsCookieName = ".AspNetAuth"; var formsCookie = Request.Cookies[formsCookieName]; if (formsCookie != null) { converter.Cookies[formsCookieName] = formsCookie; } var icustomize = report as ICustomizeHtmlToPdf; if (icustomize != null) { icustomize.Customize(converter); } return(converter.Execute()); }