.NET Core 上的 NReco HtmlToPdfConvertor 抛出 HttpContext 异常
NReco HtmlToPdfConvertor on .NET Core throws HttpContext exception
当我在 .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.
}
它抛出一个
Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
直接声明它。
有人用过 nReco 吗?
我在 .Net Core 中使用它并参考了 NReco.PdfGenerator.LT
nuget 包,用于 Html 从 NReco 到 PDF 的转换。
使用这个:
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
当我在 .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.
}
它抛出一个
Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
直接声明它。
有人用过 nReco 吗?
我在 .Net Core 中使用它并参考了 NReco.PdfGenerator.LT
nuget 包,用于 Html 从 NReco 到 PDF 的转换。
使用这个:
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