Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

JsReport Page Number with Chrome-pdf recipe

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...