WKHTMLTOPDF: How to disable header on the first page

Viewed 18789

wkhtml doesn´t repeat table elements "th" on every page like it should. So I thought it could be possible to simply use the --header-html option and add the table headers manually this way. But I don´t want them on the first page, since there are table headers already, plus some other first page stuff... I found some JS solution, but its too much complicated for me, since I know just the very basics of JS... Any ideas?

5 Answers

I faced similar problem in which I had used WKHTMLTOPDF header/footer and I wanted to remove them from the cover page. The issue was that the maximum height of header/footer was still appearing on all pages including the cover page.

The solution that clicked my mind and saved the day was that I generated two WKHTMLTOPDF files, one with header/footer on all pages and the other one without any header/footer. I then picked cover page from WKHTMLTOPDF generated file without header/footer and rest of the pages from the other WKHTMLTOPDF generated file with header/footer on all pages. I used PDF Merger library in PHP to merge selected pages of two WKHTMLTOPDF generated 'PDF' files to generate single PDF file with cover page and header/footer on rest of the pages.

<script type="text/javascript"> 
    var pdfInfo = {};
    var x = document.location.search.substring(1).split('&');

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

    function getPdfInfo() {
        var page = pdfInfo.page || 1;

        if(page != 1) {
            document.getElementById('pHeader').style.display = 'none';
        }
    }
    getPdfInfo();
</script>

For some reason, Nenotlep's answer didn't worked for me. It removed only page number..

So I created a class with a display: none; and simply added it. It worked this way.

function pagination() {
  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]];

    if (vars['page'] == 1) {
      var element = document.getElementById("pager");
      element.classList.add("pager-hidden");
    }
  }

}
.pager {
  font-size: 0.09375in;
  padding-right: 1.00003in;
  text-align: right;
  letter-spacing: 0.01042in;
  padding-bottom: 0.37501in;
}

.pager.pager-hidden {
  display: none;
}
<body onload="pagination()">

  <div class="pager" id="pager">
    <div class="pager-pages">Page <span class="page"></span> / <span class="topage"></span></div>
  </div>

</body>

Related