В документах говорится, что jsreport выполняет функцию номера страницы и общего количества страниц с {#pageNum}/{#numPages}
. Но это работает только с фантомным рецептом.
Я спрашиваю, как получить эти атрибуты в chrome-рецепте.
Еще один документ для хром-рецепт . Я уже пытался вставить следующее в шаблон html, но все равно не повезло, так как он жалуется на неопределенные страницы в функции index.js. Любая помощь будет оценена.
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
А вот мои примеры кодов:
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>