在 ASP.NET Core 中将 HTML 导出为 PDF 时出现 Microsoft Edge 问题

Microsoft Edge issue on export HTML to PDF in ASP.NET Core

我正在尝试从 ASP.Net Core Web 项目的 Html 生成 pdf。我在网上没有找到太多关于这个的信息。大多数软件包还没有为 asp.net 核心做好准备。浏览了几天,我发现 this How to export HTML to PDF in ASP.NET Core

我已经下载了项目

Export to pdf works perfectly on chrome but not on Edge; It just never finished the export.

Edge 和 pdf 有什么问题吗?我没有在 node.js 上做太多工作,所以不确定出了什么问题。任何帮助将不胜感激。在这里,我还添加了 pdf.js

中的代码
module.exports = function (callback, html) { 
    var jsreport = require('jsreport-core')(); 

    jsreport.init().then(function () { 
        return jsreport.render({ 
            template: { 
                content: html, 
                engine: 'jsrender', 
                recipe: 'phantom-pdf' 
            } 
        }).then(function (resp) { 
            callback(null, resp.content.toJSON().data); 
        }); 
    }).catch(function (e) { 
        callback(e, null); 
    }) 
}; 

和 package.json 用于 nodejs

{ 
  "name": "pdf", 
  "version": "1.0.0", 
  "description": "", 
  "main": "index.js", 
  "dependencies": { 
    "jsreport-core": "^1.3.1", 
    "jsreport-phantom-pdf": "^1.4.4", 
    "jsreport-jsrender": "^1.0.2" 
  }, 
  "devDependencies": {}, 
  "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
  }, 
  "author": "", 
  "license": "ISC" 
} 

已更新

@Martin Beeby 在控制器代码上找到问题。以下代码不适用于 MS Edge

public class HomeController : Controller
{
    [HttpGet]
    public async Task<IActionResult> Index([FromServices] INodeServices nodeServices)
    {
        HttpClient hc = new HttpClient();
        var htmlContent = await hc.GetStringAsync($"http://{Request.Host}/report.html");

        var result = await nodeServices.InvokeAsync<byte[]>("./pdf", htmlContent);

        HttpContext.Response.ContentType = "application/pdf";

        HttpContext.Response.Headers.Add("x-filename", "report.pdf");
        HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "x-filename");
        HttpContext.Response.Body.Write(result, 0, result.Length);
        return new ContentResult();
    }
}

如果您将控制器代码更改为:

public async Task<IActionResult> Index([FromServices] INodeServices nodeServices)
{
    HttpClient hc = new HttpClient();
    var htmlContent = await hc.GetStringAsync($"http://{Request.Host}/report.html");

    var result = await nodeServices.InvokeAsync<byte[]>("./pdf", htmlContent);

    return File(result, "application/pdf", "report.pdf");
}

然后在Chrome中运行,提示在Edge中下载