14

I want to convert HTML code to Image(png/jpg) on Web Server and then send image link in email in my .NET Core application. I don't want to purchase any third party library like NReco or EVo.

Is there any other way to convert HTML To Image in dotnet core 2.0?

Kristoffer Jälén
  • 4,112
  • 3
  • 30
  • 54
N P
  • 165
  • 1
  • 1
  • 6

4 Answers4

23

I use net-core-html-to-image library that embeds wkhtmltoimage tool. The library is very simple to use. There is a nuget package:

Install-Package CoreHtmlToImage

If you want to convert HTML string to image:

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

Or for URLs:

var converter = new HtmlConverter();
var bytes = converter.FromUrl("http://google.com");
File.WriteAllBytes("image.jpg", bytes);
Andrei
  • 42,814
  • 35
  • 154
  • 218
2

I know this is old but I wanted to save some from headaches if you come across it. The wkhtmltopdf.exe file that this uses, uses an older rendering engine. I had to go all the way back to bootstrap v2 to make it render correctly.

0

There are number of free libraries on web to convert HTML to image/PDF/other formats.

I prefer TuesPechkin dll to export to image/pdf.

For image you need to use wkhtmltoimage dll. You can go through below links: https://wkhtmltopdf.org/

Below is the Github link. You can find more details here: https://github.com/tuespetre/TuesPechkin

Rajesh KP
  • 17
  • 8
0

Sharing you the solution, which might helps to others

I used wkhtmltopdf.exe and it worked.

Following post helped me

https://beeming.net/just-coding/2017/5/converting-html-to-pdf-using-c-and-magic

N P
  • 165
  • 1
  • 1
  • 6