带有Chrome-pdf配方的JsReport页码

时间:2018-08-31 10:14:34

标签: jsreport

文档说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>

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容:{{$ pdf.pageNumber}} / {{$ pdf.pages.length}}

答案 1 :(得分:0)

一年后,我再次在托盘中找到了该帖子。 而且我找到了正确的方法。

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

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