0

I'm currently coding in Visual Studio 2015. It's for a school project and I need to download a view as a PDF. I tried using a lot of methods posted here but can't seem to get it to work. It's a simple view with information displayed from tables in a view and I want to download the view as a PDF. Any easy suggestions.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Evan Govender
  • 33
  • 1
  • 5
  • 1
    First easy suggestion is to show some code you've tried so far, alongside with the errors you've got. – iehrlich Jul 10 '17 at 00:43

3 Answers3

0

if you mean convert html to pdf, you can refer to below post

Convert HTML to PDF in .NET

Huan Jiang
  • 247
  • 4
  • 13
0

Actually your question is not clear. Anyways if you have that pdf file you may achieve that with FileResult method in Controller Refer this

Or else if you want that particular view as it exactly as in pdf u may add a Save as PDF button in your page and make that button action same as Ctrl+P action as PDF.

Or else if you want another way please review your question and provide correct requirements.

Luqman
  • 139
  • 2
  • 15
0

How to download an MVC view as a PDF? using Rotativa

  1. Install NuGet Package
Install-Package Rotativa -Version 1.7.4-rc
  1. C# MVC
//UserController
public ActionResult Download(string encryptReportId)
{
    //business login to bind this view
    //bind view using this encryptReportId
    return View();
}

public ActionResult DownloadViewAsPDF(string encryptId)
{
    return new Rotativa.ActionAsPdf("Download", new { encryptReportId = encryptReportId }) { FileName = "TestingPdf.pdf" };
}
  1. Html
//use ajax call for this DownloadViewAsPDF of User Controller
$.ajax({
    url: "/User/DownloadViewAsPDF",
    data: {
        encryptId ': id,//id can be get on download button click event as a parameter
    },
    type: "GET",
    contentType: "application/json;charset=utf-8",
    dataType: "json",
    success: function(result) {
        alert("Report Downloaded as PDF!!");
    },
    error: function(errormessage) {
        alert(errormessage.responseText);
    }
});

I hope this will help.

vishpatel73
  • 317
  • 4
  • 10