Skip to content

Instantly share code, notes, and snippets.

@NikolayIT
Last active February 6, 2020 15:21
Show Gist options
  • Save NikolayIT/151b39bd1fe53804fa83a844b3abc5fb to your computer and use it in GitHub Desktop.
Save NikolayIT/151b39bd1fe53804fa83a844b3abc5fb to your computer and use it in GitHub Desktop.
private readonly IViewRenderService viewRenderService;
private readonly IHtmlToPdfConverter htmlToPdfConverter;
private readonly IHostingEnvironment environment;
public DashboardController(
IViewRenderService viewRenderService,
IHtmlToPdfConverter htmlToPdfConverter,
IHostingEnvironment environment)
{
this.viewRenderService = viewRenderService;
this.htmlToPdfConverter = htmlToPdfConverter;
this.environment = environment;
}
[HttpGet]
public async Task<IActionResult> GetPdf(SomeInputModel input)
{
var model = this.GetViewModel(input);
var htmlData = await this.viewRenderService.RenderToStringAsync("~/Views/Dashboard/GetPdf.cshtml", model);
var fileContents = this.htmlToPdfConverter.Convert(this.environment.ContentRootPath, htmlData);
return this.File(fileContents, "application/pdf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment