JsReport Page Number with Chrome-pdf recipe



文件说jsreport提供页码和总页数功能,并带有{#pageNum}/{#numPages}。但这仅适用于幻影配方。

我问如何在铬配方中获得这些属性。 另一个关于铬配方的文件。我已经尝试将以下内容放入 html 模板中,但仍然没有运气,因为它抱怨索引函数中未定义的页面.js。任何帮助将不胜感激。

Page&nbsp;<span class="pageNumber"></span>&nbsp;of&nbsp;<span class="totalPages"></span>

这是我的示例代码:

索引.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);
});;
});
...

测试.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&nbsp;<span class="pageNumber">{{mySum}}</span>&nbsp;of&nbsp;<span class="totalPages">{{totalPages}}</span>
</div>

你可以使用类似的东西: {{$pdf.pageNumber}}/{{$pdf.pages.length}}

一年后,我再次在我的托盘中找到了这篇文章。 我已经找到了正确的方法。

Page&nbsp;<span class="pageNumber"></span>&nbsp;of&nbsp;<span class="totalPages"></span>

只需将这一行放在 html 模板中,一切正常。

最新更新