1) Install Install-Package Select.HtmlToPdf
We can directly install rotativa using package manager console (i.e View-> Package Manager Console) and then type ---in console ---Install-Package Select.HtmlToPdf
Or
We can do by searching it from Nuget package manager (i.e Project-> Manage Nuget Packages-> search nuget-> Install).
In Installed just update that installed Select.HtmlToPdf.
Create below actions. Index action is default action provided by Visual Studio. GetPdfaction is used to generate the PDF of Index action using SelectPDF API.
As shown in above code, we create an instance of HtmlToPdf() and then call its ConvertUrl(string url) to do the conversion. We write PdfDocument (output of ConvertUrlmethod) to HttpResponse stream. Finally close the document to release all the resources.
Run the application and navigate to /Home/GetPdf. We should get the PDF document as shown below.
Now lets make small changes in Index action to support Session usa
No comments:
Post a Comment