Esempio n. 1
0
        public ActionResult Pdf(string id)
        {
            var country    = _countryService.GetCountryViewModel(id);
            var htmlString = this.RenderPartialViewToString("pv_country_print_template", country);

            var fullFileName = "";

            try
            {
                if (Request.Url != null)
                {
                    var fileName = UrlHelper.GenerateContentUrl(
                        $"~/content/assets/{country.CountryCode}.pdf", HttpContext);
                    fullFileName = Server.MapPath(fileName);

                    var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
                    PdfService.Create(htmlString, fullFileName, baseUrl, country.CountryName);
                }
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }

            return(File(fullFileName, "application/pdf", country.CountryName + ".pdf"));
        }