带有Chrome-pdf配方的JsReport页码 [英] JsReport Page Number with Chrome-pdf recipe

查看:200
本文介绍了带有Chrome-pdf配方的JsReport页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说jsreport使用{#pageNum}/{#numPages}来提供页码和总页数功能.但这仅适用于幻影配方.

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.

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

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>

这是我的示例代码:

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

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>

推荐答案

一年后,我再次在任务栏中找到了该帖子. 而且我找到了正确的方法.

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>

只需将这一行放在html模板中,一切就可以了.

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

这篇关于带有Chrome-pdf配方的JsReport页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆