Search code examples
javascriptc#jqueryasp.net-mvcrotativa

Hide Print button and nav menu in PDF using Rotativa PDF generator in Asp MVC 5


I want to convert the page content to PDF. So that I have installed nuget package rotativa and when I try to print a view It shows the entire page in PDF along with the print button. I don't want show the print button and navigation menu in my desired output PDF.

The image of current output PDF


Solution

  • To achieve this I have created new view (Preview.cshtml) which contains the data which I need to export as PDF.

    public ActionResult ExportCvPdf()
    {
        string switches = string.Format("--disable-smart-shrinking --header-html {0} --footer-html {1}",
         Url.Action("Header", "Cotroller", new { area = "Areaname" }, "http"),
         Url.Action("Footer", "Cotroller", new { area = "Areaname" }, "http"));
    
        return new Rotativa.ViewAsPdf("Preview", data)
          {
            FileName = "Sample-" + DateTime.Now.ToString("yyyyMMdd") + ".pdf",
            PageSize = Size.A4,
            PageMargins = new Margins(30, 15, 20, 15),
            CustomSwitches = switches
          };
    
    }
    
    public ActionResult Preview(ViewModel detail)
    {
      return View(detail);
    }