织梦CMS - 轻松建站从此开始!

abg欧博官网|登陆|游戏|

The best HTML to PDF converter in ASP.NET Core 6.

时间:2025-11-26 20:02来源: 作者:admin 点击: 13 次
You can use Syncfusion to convert html to pdf. First, Install Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package. Then, Edit the corresponding me

You can use Syncfusion to convert html to pdf.

First, Install Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package.

Then, Edit the corresponding method in the controller:

public class HomeController : Controller { public IActionResult Index() { return View(); } public IActionResult ExportToPDF() { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to PDF document PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); //Create memory stream MemoryStream stream = new MemoryStream(); //Save the document document.Save(stream); return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTML-to-PDF.pdf"); } }

Don't forget to add the namespace:

using Syncfusion.Pdf; using Syncfusion.HtmlConverter;

Finally, Add the call in Index.cshtml:

@{ Html.BeginForm("ExportToPDF", "Home", FormMethod.Post); { <div> <input type="submit" value="Convert HTML to PDF" style="width:250px;height:27px" /> </div> } Html.EndForm(); }

You can change the URL Page you want to download in the controller method:

PdfDocument document = htmlConverter.Convert("Your Url");

For more details, you can refer to this document.

Update:

Yes, it's not actually open source, you need to get a license key to remove it (only 30 days free trial).

Free and effective first choice is actually SelectPDF.

If you really don't want to use it, you can choose the following two:

PuppeteerSharp: It's a headless chrome instance which can capture pdfs, and has a nice C# library (Puppeteer Sharp).

jsPDF: This is also a conversion tool used by open source.

Just my opinion, I think the experience of these two is not as good as SelectPDF. Maybe there are other free and up-to-date PDF converters, but I haven't found them and haven't used them.

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-12-14 14:12 最后登录:2025-12-14 14:12
栏目列表
推荐内容