Search code examples
jqueryhtmlasp.net-mvc-4rotativa

All pages with header excluding first page - RotativaPDF


I'm trying to create a exportable/printable page with RotativaPDF where those pages must have a small section with some data from a customer, tables with customer credits and payments, and every page must have a footer and a header (excluding the first page).

My controller's action:

public ActionResult ExportToPDF()
    {
        var customer= new Customer();
        var customerData = string.Format("Name: {0} | Client Nr.: {1}", customer.Name, customer.CardNumber);
        return new ActionAsPdf("ExportPDF")
        {
            CustomSwitches = "--footer-right \"[page]/[topage]\" " +
                             "--footer-left \"Emission date: [date]\" " +
                             "--header-right \""+ customerData + "\" " +
                             "--header-left \"Customer Data\" " +
                             "--footer-font-size \"11\" " +
                             "--header-font-size \"11\" " +
                             "--footer-spacing \"10\" " +
                             "--header-spacing \"20\""
        };
    }

Note: I defined CustomSwitches like is described on this link.

With my code, all the pages presents a header. How should I do to not present a header on the first page?

Expected result: Expected result


Solution

  • Found an answer @ Hide Footer on first page

    Know its very late reply but may help someone

    So to hide the header in the firstpage I used like this

    <!DOCTYPE html>
    <html>
       <head>
          <script>
             function subst() {
                 var vars = {};
                  // explore the URL query string  
                 var x = document.location.search.substring(1).split('&');
                 // loop through each query string segment and get keys/values 
                 for (var i in x) {
                     var z = x[i].split('=', 2);
                     vars[z[0]] = unescape(z[1]);
                 }
                  // an array of all the parameters passed into the footer file  
                 var x = ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];
    
                 // each page will have an element with class 'section' from the body of the footer HTML  
                 var y = document.getElementsByClassName('section');
                 for (var j = 0; j < y.length; j++) {
                     // if current page equals first page  
                     if (vars[x[2]] == 1) {
                         y[j].innerHTML = "";
                         document.getElementsByClassName('section').style.display = 'none';
                     }
                 } 
             }
          </script>
       </head>
       <body style="border: 0; margin: 0;" onload="subst()">
          <table style="width: 100%;" border="0"  class="section">
             <tr>
                <td>My header</td>
             </tr>
          </table>
       </body>
    </html>