Converting razor view into PDF file

Hi,

Hello,

I have a .Net core project (MVC design - .net 7). I would like the user to be able to download a razor view as a PDF file.

The razor view uses a layout.cshtml file where all the css, js, images files are referenced. The view is also dynamic (reads data from model).  The button to convert the html to PDF will be on the same razor view.

What is the best way to convert this razor view into a PDF file with the 

Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package ?

It seems there are two approaches : either get the html document of the current view as a string via Javascript and then send to server-side or instantiate a web client on server side which calls the razor page and download the resulting html as a string. Let me know what method you recommend and potentially provide code sample.

Thanks for the help !


1 Reply

KS Karmegam Seerangan Syncfusion Team May 14, 2024 06:52 AM UTC

Hi Loic,

Thank you for reaching out to Syncfusion support.

 

Our HTML converter library internally uses the Blink rendering engine. It utilizes a Chrome headless browser for converting HTML to PDF. It will preserve the PDF document in the same way as the input HTML/URL is displayed in Chromium-based web browsers such as Chrome and print preview. Our converter replicates this same behavior. Therefore, we can utilize any of the methods available to convert the razor view into a PDF document according to your preference.

 

Please find the below documentation for further information.

How to convert MVC View to PDF using C# in ASP.NET Core? (syncfusion.com)

Convert ASP.NET Core web Razor page to PDF

Convert ASP.NET Core MVC view to PDF

 

Kindly try the provided solution and get back to us if you need further assistance.


Regards,

Karmegam



Loader.
Up arrow icon