如何获得 wkhtmltopdf 正文中的总页数? [英] How do I get total pages in wkhtmltopdf body?
问题描述
是否可以访问主要内容正文中的topage"变量?
Is it possible to access the "topage" variable within the main content body?
我知道您可以在页眉和页脚中执行此操作,但在此特定用例中,我需要在正文中放置一个句子:
I know you can do it in headers and footers but in this specific use case, I need to put a sentence within the body that says:
此文档包含 XX 页".
"This document contains XX pages".
推荐答案
这对我有用.但需要在页眉(ou页脚)在正文中,我认为这是不可能的,就像他们在 GitHub 中所说的那样http://github.com/wkhtmltopdf/wkhtmltopdf/issues/1889
This works to me. But need to be in the header (ou footer) In the body I think it is not possible, like they said in the GitHub http://github.com/wkhtmltopdf/wkhtmltopdf/issues/1889
要将此信息放在页脚中,您可以在此链接中看到@Unixmonkey:https://github.com/mileszs/wicked_pdf#page-numbering
To put this info in the footer you can see @Unixmonkey in this link: https://github.com/mileszs/wicked_pdf#page-numbering
<html>
<head>
<script>
function number_pages() {
var vars={};
var x=document.location.search.substring(1).split('&');
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = decodeURIComponent(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 onload="number_pages()">
Page <span class="page"></span> of <span class="topage"></span>
</body>
</html>
这篇关于如何获得 wkhtmltopdf 正文中的总页数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!