JsReport Page Number with Chrome-pdf recipe

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 04:09:32

问题


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

回答1:


You can use something like: {{$pdf.pageNumber}} / {{$pdf.pages.length}}




回答2:


After one year, i found this post in my tray again. And I have found the correct way to do.

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

Just put this line inside the html template and everything is ok.



来源:https://stackoverflow.com/questions/52113255/jsreport-page-number-with-chrome-pdf-recipe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!