public async Task <FileStreamResult> RenderAsync <T>(string viewPath, T model) { string html = await _renderer.RenderAsync(viewPath, model); var stream = _streamManager.GetStream(); var result = await Command.Run("weasyprint", new[] { "--format=pdf", "-", "-" }, opts => opts.WorkingDirectory(_environment.WebRootPath)) .RedirectFrom(html) .RedirectTo(stream) .Task; if (!result.Success) { throw new Exception(result.StandardError); } stream.Position = 0; return(new FileStreamResult(stream, contentType: "application/pdf")); }