首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Angular 10的JSReport新手

使用Angular 10的JSReport新手
EN

Stack Overflow用户
提问于 2021-06-07 22:56:14
回答 1查看 112关注 0票数 0

我正在使用Angular 10,想将JSReport插入到我的程序中以打印报告(pdf)。对于JSReport,我已经设置了服务器,创建了一个示例报告,并使用'postman‘测试它,一切正常。并且Angular已经下载( npm install jsreport-browser-client-dist ),并得到以下代码:

代码语言:javascript
复制
    grdInvoiceMToolbarPrint() {
    this.ProSvr.GetRpInvoice(this.AuthSvr.branchID, "INV5000000050").subscribe((rMsg: ResponseMessage) => {
      this.rpInvoice = [];
      this.rpInvoice = (rMsg.data as RpInvoice[]);

      const request = {
        'template': { "name": "invoice" },
        'data': JSON.stringify(this.rpInvoice)
      };

      
      //this.jsreport.serverUrl = this.ProSvr.urlReport;
      //this.jsreport.headers['Authorization'] = 'Basic ' + btoa('admin:password');
  
      // this.jsreport.renderAsync(request).then(function(res) {
      //   const html = '<html>' +
      //           '<style>html,body {padding:0;margin:0;} iframe {width:100%;height:100%;border:0}</style>' +
      //           '<body>' +
      //           '<iframe type="application/pdf" src="' +  res.toDataURI() + '"></iframe>' +
      //           '</body></html>';
      //   const a = window.open('about:blank', 'Report');
      //   a.document.write(html);
      //   a.document.close();
      // });
      
      console.log(JSON.stringify(this.rpInvoice));
    });
  }

我已经阅读了文档https://jsreport.net/learn/browser-client,但没有提到任何内容。到目前为止,我无法继续,因为'this.jsreport‘没有定义,请帮助!

EN

回答 1

Stack Overflow用户

发布于 2021-06-09 11:12:43

代码语言:javascript
复制
import * as jsReport from 'jsreport-browser-client-dist';
...
...
 grdInvoiceMToolbarPrint() {
this.Svr.GetRpInvoice(this.AuthSvr.branchID, "INV5000000050").subscribe((rMsg: ResponseMessage) => {
  this.rpInvoice = [];
  this.rpInvoice = (rMsg.data as RpInvoice[]);

  const request = {
    'template': { "name": "invoice" },
    'data': JSON.stringify(this.rpInvoice)
  };
  jsReport.serverUrl = this.Svr.urlReport;
  jsReport.renderAsync(request).then(function(res) {
    window.open(res.toDataURI())
  });
});

}

*导入* as jsReport XXXXXXX可以改为导入* as abcXyz XXXXXXXX

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67873974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档