【问题标题】:NReco HtmlToPdfConvertor on .NET Core throws HttpContext exception.NET Core 上的 NReco HtmlToPdfConvertor 引发 HttpContext 异常
【发布时间】:2022-01-18 06:01:47
【问题描述】:

当我在 .Net Core 2.0 Mvc 应用程序中声明 NReco.PdfGenerator 时出现错误。

  • 我将 Nuget 包 NReco.PdfGenerator 1.1.15 添加到项目中
  • 在控制器中做了一个 using 语句
  • 声明 HtmlToPdfConverter

[HttpPost]
public IActionResult Index(myModel model)
{
    var html2PdfConverter = new NReco.PdfGenerator.HtmlToPdfConverter();
      
    // etc.   
}

它抛出一个

无法从程序集“System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.HttpContext”

直接声明它。

有人使用过 nReco 吗?

【问题讨论】:

    标签: c# .net-core nreco


    【解决方案1】:

    我在 .Net Core 中使用它并引用 NReco.PdfGenerator.LT nuget 包,用于从 NReco 将 Html 转换为 PDF。

    【讨论】:

    • NReco.PdfGenerator.LT 需要许可证密钥
    【解决方案2】:

    使用这个:

    var converter = new HtmlConverter();
    var html = "<div><strong>Hello</strong> World!</div>";
    var bytes = converter.FromHtmlString(html);
    File.WriteAllBytes("image.jpg", bytes);
    

    你需要安装包:

    Install-Package CoreHtmlToImage
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 2019-11-12
      相关资源
      最近更新 更多