NReco HtmlToPdfConvertor on .NET Core throws HttpContext exception
Asked Answered
P

2

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?

Palmate answered 14/2, 2018 at 13:40 Comment(0)
P
4

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

Pettway answered 14/2, 2018 at 14:8 Comment(1)
NReco.PdfGenerator.LT requires a license keyGendarmerie
P
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
Perfective answered 17/1, 2022 at 22:1 Comment(3)
Are you suggesting converting it to an image rather than pdf?Keyway
converting image to pdf is easy,Perfective
This question is about using NReco, and automating the creation of the PDF.Keyway

© 2022 - 2024 — McMap. All rights reserved.