Footers And Headers

Headers and footers can be added to the document by the --header-* and --footer* arguments respectfully. In header and footer text string supplied to e.g. —header-left, the following variables will be substituted.

  • [page] Replaced by the number of the pages currently being printed
  • [frompage] Replaced by the number of the first page to be printed
  • [topage] Replaced by the number of the last page to be printed
  • [webpage] Replaced by the URL of the page being printed
  • [section] Replaced by the name of the current section
  • [subsection] Replaced by the name of the current subsection
  • [date] Replaced by the current date in system local format
  • [isodate] Replaced by the current date in ISO 8601 extended format
  • [time] Replaced by the current time in system local format
  • [title] Replaced by the title of the of the current page object
  • [doctitle] Replaced by the title of the output document
  • [sitepage] Replaced by the number of the page in the current site being converted
  • [sitepages] Replaced by the number of pages in the current site being converted

As an example specifying —header-right “Page [page] of [toPage]”, will result in the text “Page x of y” where x is the number of the current page and y is the number of the last page, to appear in the upper left corner in the document.

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:

  1. <html><head><script>
  2. function subst() {
  3. var vars = {};
  4. var query_strings_from_url = document.location.search.substring(1).split('&');
  5. for (var query_string in query_strings_from_url) {
  6. if (query_strings_from_url.hasOwnProperty(query_string)) {
  7. var temp_var = query_strings_from_url[query_string].split('=', 2);
  8. vars[temp_var[0]] = decodeURI(temp_var[1]);
  9. }
  10. }
  11. var css_selector_classes = ['page', 'frompage', 'topage', 'webpage', 'section', 'subsection', 'date', 'isodate', 'time', 'title', 'doctitle', 'sitepage', 'sitepages'];
  12. for (var css_class in css_selector_classes) {
  13. if (css_selector_classes.hasOwnProperty(css_class)) {
  14. var element = document.getElementsByClassName(css_selector_classes[css_class]);
  15. for (var j = 0; j < element.length; ++j) {
  16. element[j].textContent = vars[css_selector_classes[css_class]];
  17. }
  18. }
  19. }
  20. }
  21. </script></head><body style="border:0; margin: 0;" onload="subst()">
  22. <table style="border-bottom: 1px solid black; width: 100%">
  23. <tr>
  24. <td class="section"></td>
  25. <td style="text-align:right">
  26. Page <span class="page"></span> of <span class="topage"></span>
  27. </td>
  28. </tr>
  29. </table>
  30. </body></html>

As can be seen from the example, the arguments are sent to the header/footer html documents in get fashion.