带有 Chrome-pdf 配方的 JsReport 页码

JsReport Page Number with Chrome-pdf recipe

文档说 jsreport 使用 {#pageNum}/{#numPages} 提供页码和总页数功能。但这只适用于幻影食谱。

我问的是如何在 chrome-recipe 中获取这些属性。 chrome-recipe 的另一个文档。我已经尝试将以下内容放入 html 模板中,但仍然没有成功,因为它抱怨 index.js 函数中未定义的页面。任何帮助将不胜感激。

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

您可以使用类似:{{$pdf.pageNumber}} / {{$pdf.pages.length}}

一年后,我又在我的托盘里找到了这个post。 而且我找到了正确的方法。

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

只需将此行放在 html 模板中即可。