Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

How to print page number alternatively #3708

Open
vishnushanmughan opened this issue Nov 7, 2017 · 6 comments
Open

How to print page number alternatively #3708

vishnushanmughan opened this issue Nov 7, 2017 · 6 comments
Labels

Comments

@vishnushanmughan
Copy link

I have two question regarding the page number

  1. Is there any way to print the page number left and right alternatively
  2. Is it possible to start the page number from where we want. fx: if we want to show the page number from the 6th page hide all the page number before it
@drfish
Copy link

drfish commented Nov 8, 2017

I'm not one of the devs so there may be an easier way to do this (I've never done it myself), but if you use a header/footer based on an html file, you ought to be able to do some clever stuff with javascript based on page numbers. Check out the example on the man page: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt search for "subst()" and you'll see a slightly more complex header example. starting from that then it should just be a matter of stripping out the ones you don't care about and adding some logic to the ones you do. Still requires a bit of fiddling, but it should work?

@RaulTsc
Copy link

RaulTsc commented Nov 23, 2017

This is what we use to reset numbering when we encounter a h1 tag:

<!DOCTYPE html>
<html>
  <head>
    <script>
      function setPageNumbers() {
        /*
          vars will have the following structure

          vars: {
            page,
            frompage,
            topage,
            webpage,
            section,
            subsection,
            date,
            isodate,
            time,
            title,
            doctitle,
            sitepage,
            sitepages
          }
        */
        var vars = {};
        var queryStringsFromUrl = document.location.search.substring(1).split('&');
        for (var queryString in queryStringsFromUrl) {
            if (queryStringsFromUrl.hasOwnProperty(queryString)) {
                var temp = queryStringsFromUrl[queryString].split('=', 2);
                vars[temp[0]] = decodeURI(temp[1]);
            }
        }

        var element = document.getElementById('pageNumber');

        if (document.cookie.split(';').length === 2) {
          var section = document.cookie.split(';')[0].split('=')[1];

          if (vars.section !== section) {
            document.cookie = 'currentSection=' + vars.section;
            document.cookie = 'startedAt=' + vars.page;
          }

          // startedAt is the page on which a section started
          var startedAt = parseInt(document.cookie.split(';')[1].split('=')[1]);
          element.textContent = vars.page - startedAt + 1;
        } else {
          document.cookie = 'currentSection=' + vars.section;
          document.cookie = 'startedAt=' + vars.page;
          element.textContent = 1;
        }
      }
    </script>
  </head>
  <body style="text-align: center; padding-bottom: 16px" onload="setPageNumbers()">
    <p style="font-size: 12px">- <span id="pageNumber"></span> -</p>
  </body>
</html>

It's basically the example from the documentation enhanced a bit.

@toxaus
Copy link

toxaus commented Feb 8, 2018

Good advice here, thank you!
Any idea how to show correct number of pages("topage"), if we are using this resetting of current pageNumber("page")? Its simple for all "Last" sections in document, but cant do it for "First" section (when we don't know about further sections)

@alloylab
Copy link

alloylab commented Jul 5, 2018

is this still an issue on 0.12.5?

@enotuniq
Copy link

@RaulTsc thank you we set the page numbers but do you have any idea for table of contents?
How can we sync page numbers in toc with in document?
For example "some heading" page number is "3-5" but 18 in toc.

@RaulTsc
Copy link

RaulTsc commented Jan 28, 2019

@enotuniq sorry man but this was a long time ago, I can't help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

6 participants