6

When I declare the NReco.PdfGenerator in a .Net Core 2.0 Mvc application I get an error.

  • I added the Nuget package NReco.PdfGenerator 1.1.15 to the project
  • Made a using statement In the controller
  • Declare the HtmlToPdfConverter

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

It throws a

Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

directly on declaring it.

Has someone had experience with nReco?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Stefan de Groot
  • 364
  • 1
  • 4
  • 12

2 Answers2

4

I use this in .Net Core and reference the NReco.PdfGenerator.LT nuget package for Html to PDF conversion from NReco.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mark Redman
  • 24,079
  • 20
  • 92
  • 147
1

use this:

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

you need to install package:

Install-Package CoreHtmlToImage