Search code examples
c#asp.net-mvcrotativa

Rotativa 1.7.4 ActionAsPDF, Remove Navbar and Print button


I am trying to remove the navbar and print button from the page that I am trying to print. I attempted to use CustomSwitches but Rotativa does not appear to like them.

string customSwitches = 
    "--disable-smart-shrinking --header-html {0} --footer-html {1}";

var printForm = new ActionAsPdf("Receipt", new { id = id })
{
    PageSize = Rotativa.Options.Size.Legal,
    CustomSwitches = customSwitches
};

return printForm;

My view for reference: Print view.

What are some thoughts?


Solution

    1. You can use --print-media-type custom switch.
    2. Apply the class no-print for your navbar div and button

    Then write your CSS like this

    @media print
    {    
        .no-print, .no-print *
        {
            display: none !important;
        }
    }