JavaScript Required

We're sorry, but we doesn't work properly without JavaScript enabled.

Contact Us: #technoligent

Global Presence

  • USA
  • Canada
  • Europe
  • UK
  • Singapore
  • Hong Kong
  • Japan
  • UAE
  • Australia
  • New Zeeland
  • Saudi Arabia
You Are Here : Home Articles

How to generate PDF from MVC page in development

How to generate PDF from MVC page in development

Technoligent professionals have shared many tutorials to make the job of developers easy. In this article, they will explain how to generate PDF file from MVC page and send email using generated PDF as attachment. Read and learn step-by-step in this tutorial and make best practices for development. They have also shared the things you may need before commencing the project.

For this task I will create one partial view in MVC 4 project that contains one text box and some questions with two options. Also, I am using Rotativa library to convert .cshtml page to PDF, you can get this library from NuGet package.

First start with MVC project, create a MVC 4 project. Add one model as below and name it “GeneratePDFModel”.

Add following code to GeneratePDFModel class as below and inherit PartialViewAsPdf class from Rotativa library. It is a main class which generate PDF file from .cshtml page. Main purpose of this code is the PartialViewAsPdf will return a PDF file, but we want a byte array to create attachment file for email.

To include Rotativa library in your project execute following command to Package Manager Console.


Next step is to add following key values to in webconfig file.

Add Index view as below and update design as per requirement.

Then add Partial view to Home folder and design as below.

Now, create ActionResult which execute HttpPost method for Index page in Home Controller with model as input parameter.

Above code will get content from Partial view and generate PDF file using ViewAsPdf2 method then send email to specified email address with newly generated PDF file as attachment.

Following is the output of index view.

And following is the pdf file screenshot sent as attachment with email

You can update partial view design as per your requirement which effects content of pdf file. All the steps shared by Technoligent experts are essential to create PDF file from MVC page. You also need the things required for preparing PDFs (that is also mentioned in the post). You may share your review for this tutorial or ask query related to the subject from ASP.Net development services. Don’t forget to comment in the below section.

What Client’s Say

  • We work together with Technoligent in a mobile Project. It was not easy to develop, but the Team of Technoligent was very professional and we did a perfect solution for the european Sailors. Now we look forward to realise the next Projects together... More

    by Jorg B (Austria)
  • We found a reliable and efficient partner in Technoligent, ready to support our strategy of offshore software development. Technoligent has particularly impressed by the speed of response to any request for the development of software applications and for their maintenance... More

    by Fabio Durso

Gripping Technology, Explore Innovations

Let’s work together