4

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

Ninita
  • 1,209
  • 2
  • 19
  • 45
  • @FreeAsInBeer no, I gave up. I suppose the @ kiev answers could help but you need to know exactly where pages ends. You can find more information in http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html . Sorry for can't help you more – Ninita Dec 15 '14 at 19:30

2 Answers2

1

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>
Ninita
  • 1,209
  • 2
  • 19
  • 45
Geervani
  • 96
  • 8
0

I saw the following that may be useful in the documentation. Perhaps you can do some sort of logic to hide the first page header/footer based on page number

Headers and footers can also be supplied with HTML documents. As an example one could specify --header-html header.html, and use the following content in header.html:

<html>
    <head>
        <script>
            function subst() {
                var vars={};
                var x=document.location.search.substring(1).split('&');

                for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}

                var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];

                for(var i in x) {
                    var y = document.getElementsByClassName(x[i]);
                    for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                }
            }
        </script>
    </head>
    <body style="border:0; margin: 0;" onload="subst()">
        <table style="border-bottom: 1px solid black; width: 100%">
          <tr>
            <td class="section"></td>
            <td style="text-align:right">
              Page <span class="page"></span> of <span class="topage"></span>
            </td>
          </tr>
        </table>
    </body>
</html>
Ninita
  • 1,209
  • 2
  • 19
  • 45
kiev
  • 2,040
  • 9
  • 32
  • 54