The documents said the jsreport serves the page number and total pages function with a {#pageNum}/{#numPages}
. But this only work with the phantom recipe.
I am asking on how to get these attribute in the chrome-recipe.
Another document for chrome-recipe. I tried to put the following into the html template already, but still no luck since it is complaining about undefined pages in the index.js function. Any help would be appreciated.
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
And here are my sample codes:
index.js:
...
app.get("/test", (req, res, next) => {
client.render({
template: {
content: ReadContent("test.html"),
recipe: "chrome-pdf",
engine: "handlebars",
helpers: `
function mySum() {
return this.$pdf.pages[this.$pdf.pageIndex].items.reduce((a,c) => a + c)
}
`
},
data: {}
})
.then((response) => {
response.body((buffer) => {
//prints hello world!!
console.log(buffer.toString());
});
response.pipe(res);
})
.catch((err) => {
next(err);
});;
});
...
test.html
<div>
<h4>Random Text:</h4>
<p>On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your
document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other
document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your
current document look. You can easily change the formatting of selected text in the document text by...
</p>
</div>
<div>
<label>enoguh Internet for today</label>
Page <span class="pageNumber">{{mySum}}</span> of <span class="totalPages">{{totalPages}}</span>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…