-
Notifications
You must be signed in to change notification settings - Fork 1.8k
How to print page number alternatively #3708
Comments
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? |
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. |
Good advice here, thank you! |
is this still an issue on 0.12.5? |
@RaulTsc thank you we set the page numbers but do you have any idea for table of contents? |
@enotuniq sorry man but this was a long time ago, I can't help. |
I have two question regarding the page number
The text was updated successfully, but these errors were encountered: