Search code examples
c#wkhtmltopdfnreco

Adding page numbers to PDFs including the cover page


I'm trying to add a page number to the bottom of the page, which doesn't seem to work as expected.

Currently i'm using this:

<span class="page"></span>/<span class="topage"></span>

The problem with this solution is that it doesn't count the cover as a page.

So a 7 page PDF "has" 6 pages according to my code.

I'm looking for a way to include the Cover as a page, so the number is correct.

Currently i'm looking into some JS to manipulate it afterwards, but there have to me some "official" solution?


Solution

  • Solved using javascript. :)

    If anyone are looking for the solution here you go:

        var x=window.location.search.substring(1).split('&');
        for (var i in x) {
            var z=x[i].split('=',2);
            vars[z[0]] = unescape(z[1]);
        }
    
        var pageNumberStart = parseInt(vars.page);
        var pageNumberEnd = parseInt(vars.topage);
    
        if (pageNumberStart != null && pageNumberEnd != null) {
            document.getElementById('page').innerHTML = pageNumberStart + 1;
            document.getElementById('topage').innerHTML = pageNumberEnd + 1;
        }
    

    Maybe someone got the official way to do it? :D