【发布时间】:2018-10-12 18:21:13
【问题描述】:
标题##我想在 Web 服务器上将 HTML 代码转换为图像(png/jpg),然后在我的 .NET Core 应用程序中通过电子邮件发送图像链接。我不想购买任何第三方库,例如 NReco 或 EVo。
在 dotnet core 2.0 中有没有其他方法可以将 HTML 转换为图像?
【问题讨论】:
标签: .net-core-2.0 wkhtmltoimage
在 dotnet core 2.0 中有没有其他方法可以将 HTML 转换为图像?
【问题讨论】:
标签: .net-core-2.0 wkhtmltoimage
我使用嵌入 wkhtmltoimage 工具的net-core-html-to-image 库。该库使用起来非常简单。有一个nuget 包:
Install-Package CoreHtmlToImage
如果要将 HTML 字符串转换为图像:
var converter = new HtmlConverter();
var html = "<div><strong>Hello</strong> World!</div>";
var bytes = converter.FromHtmlString(html);
File.WriteAllBytes("image.jpg", bytes);
或者对于 URL:
var converter = new HtmlConverter();
var bytes = converter.FromUrl("http://google.com");
File.WriteAllBytes("image.jpg", bytes);
【讨论】:
我知道这是旧的,但如果你遇到它,我想避免一些头痛。此使用的 wkhtmltopdf.exe 文件使用较旧的渲染引擎。我必须一直回到 bootstrap v2 才能正确渲染。
【讨论】:
网络上有许多免费的库可以将 HTML 转换为图像/PDF/其他格式。
我更喜欢将 TuesPechkin dll 导出为图像/pdf。
对于图像,您需要使用 wkhtmltoimage dll。您可以通过以下链接: https://wkhtmltopdf.org/
以下是 Github 链接。您可以在此处找到更多详细信息: https://github.com/tuespetre/TuesPechkin
【讨论】:
分享你的解决方案,这可能对其他人有帮助
我使用了 wkhtmltopdf.exe,它成功了。
以下帖子帮助了我
https://beeming.net/just-coding/2017/5/converting-html-to-pdf-using-c-and-magic
【讨论】: