Wkhtmltopdf添加页码

为wkhtmltopdf(wkhtmltox)添加页面有两种方式。

第一种为,在下面六个参数中,传递[page]/[topage]即可。

--header-center
--header-left
--header-right
--footer-center
--footer-left
--footer-right

第二种为,为header或footer设置–header-html或–footer-html参数,从而生成页码。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  <title>footer</title>
  <script>
  function subst() {
    var vars={};
    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 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]];
    }
  }
  </script>
</head>
<body style="border:0; margin: 0;" onload="subst()">
  <table style="border-bottom: 1px solid black; width: 100%">
    <tr>
      <td style="text-align:right">
        第 <span class="page"></span> 页,共 <span class="topage"></span> 页
      </td>
    </tr>
  </table>
</body>
</html>

Comments are closed.