Code For Convert Html To Pdf In Asp.net

When you convert an ASP.NET MVC URL, the converter will make a GET request to the URL in a new session and the values stored in the current ASP.NET Session are not available. The solution is to get the HTML code rendered by the MVC view in the current context of the MVC controller and to convert that HTML code to PDF giving the appropriate base. HTML to PDF in ASP.NET - C#. The following code converts a web page using C# ASP.NET and sends the generated PDF as an HTTP response: You can also convert raw HTML code, just use the convertHtml method instead of convertURI : The API lets you also convert a local HTML file.

  1. Code For Convert Html To Pdf In Asp.net Online
  2. Code For Convert Html To Pdf In Asp.net Windows 10
  3. Code For Convert Html To Pdf In Asp.net 2016
  4. Code For Convert Html To Pdf In Asp.net 2017
Html

10 Jul 20204 minutes to read

In your ASP.NET Core application, add the following assemblies to use Essential PDF:

  • Syncfusion.Compression.Portable.dll
  • Syncfusion.Pdf.Portable.dll
  • Syncfusion.HtmlConverter.Portable.dll

For more details, refer to this Assemblies Required documentation.

By executing the program, you will get the PDF document as follows. Steps to convert HTML to PDF document using Blink in ASP.NET Core. Create a new C# ASP.NET Core Web Application project. Select Web Application pattern (Model-View-Controller) for the project. It uses the WebKit engine to convert HTML to PDF. It will allow us to create a PDF document from our HTML string that we generate in the.NET Core project, or to create a PDF document from an existing HTML page. Furthermore, we can download the created PDF document or save it on a certain location or return a new HTML page with the PDF content. Convert from Html To Pdf in ASP.NET MVC C# with SelectPdf Free Community Edition (C recipe) by SelectPdf. Take a look at the simple code below.

Html

Steps to convert HTML to PDF document using WebKit in ASP.NET Core

Create a new C# ASP.NET Core Web Application project.

Select Web Application pattern (Model-View-Controller) for the project.

Install the Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core NuGet package as reference to your .NET Standard applications from NuGet.org.

Copy the QtBinariesWindows folder from the installed HtmlToPdfConverter package and paste it into the folder which contains the HTMLtoPDF.csproj file.

Then, set Copy to output directory to copy all the QtBinariesWindows (All files including inner folders and files) assemblies.

Code

A default controller with name HomeController.cs gets added on creation of ASP.NET MVC project. Include the following namespaces in that HomeController.cs file.

A default action method named Index will be present in HomeController.cs. Right click on Index method and select Go To View where you will be directed to its associated view page Index.cshtml.

Add a new button in the Index.cshtml as shown below.

Add a new action method ExportToPDF in HomeController.cs and include the below code snippet to convert HTML to PDF file and download it.

A complete work sample can be downloaded from HtmlToPDF.zip

By executing the program, you will get the PDF document as follows.

Steps to convert HTML to PDF document using Blink in ASP.NET Core

Create a new C# ASP.NET Core Web Application project.

Select Web Application pattern (Model-View-Controller) for the project.

Install the Syncfusion.HtmlToPdfConverter.Blink.Net.Core.Windows NuGet package as reference to your .NET Standard applications from NuGet.org.

Copy the BlinkBinariesWindows folder from the installed HtmlToPdfConverter package and paste it into the folder which contains the HTMLtoPDF.csproj file.

Code For Convert Html To Pdf In Asp.net Online

Then, set Copy to output directory to copy all the BlinkBinariesWindows (All files including inner folders and files) assemblies.

A default controller with name HomeController.cs gets added on creation of ASP.NET MVC project. Include the following namespaces in that HomeController.cs file.

A default action method named Index will be present in HomeController.cs. Right click on Index method and select Go To View where you will be directed to its associated view page Index.cshtml.

Add a new button in the Index.cshtml as shown below.

Code For Convert Html To Pdf In Asp.net Windows 10

Add a new action method ExportToPDF in HomeController.cs and include the below code snippet to convert HTML to PDF file and download it.

Code For Convert Html To Pdf In Asp.net 2016

A complete work sample can be downloaded from HtmlToPDF.zip

Code For Convert Html To Pdf In Asp.net 2017

By executing the program, you will get the PDF document as follows.