General Query of JSReport with Angular 7



  • Hi , i have connected the JSReport with my angular Application.
    Right now , i'm facing the login issues , i.e. As the authentication is enabled in the JSReport server and from angular application i'm adding the Authorization header but still its asking for the login while requesting for the report.

    Below is the code

      GetDOC(data: any) {
        this.jsreport.serverUrl = 'http://localhost:5488';
        // this.jsreport.headers['Authorization'] = 'Basic ' + btoa('admin:password');
        const request = {
          //  'Authorization' : 'Basic ' + btoa('admin:password'),
          'template': { 'shortid' : 'BJl6O-vNcN'  },
          'data' : data,
          'options': { 'timeout': 60000 }
        };
    
        this.jsreport.render('_blank', request);
      }
    

    I wanted to know whether the Authorization should be placed inside the request or outside . Is the above code is the correct syntax ?

    Another thing is in the https://jsreport.net/learn/docxtemplater , i have a document where the data is in nested Array format

    object:
       data:
           submit: true
           text: "DEMO"
           text2: "DEMO"
    

    how can i use / print this in the word

    Thank you.



  • You need to use the renderAsync function. The authorization doesn't work for sync form submit based render.



  • Hi @jan_blaha Thanks for your suggestion and as you said , i've updated my code & now i'm able to receive the report without login required.
    But i have a doubt , every report received are under the name download.docx but i want to change the name as Report or some other names.
    Kindly suggest some steps which i may have missed .

    Here is the code

      GetDoc(data: any) {
        this.jsreport.serverUrl = 'http://localhost:5488';
        // add custom headers to ajax calls
        this.jsreport.headers['Authorization'] = 'Basic ' + btoa('admin:password');
    
        const request = {
          'template': { 'shortid' : 'BJl6O-vNcN'  },
          'data' : data,
          'options': {'reportName': 'General Report'}      <----  Is this the correct way of Giving the name parameter.
        };
        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();
      });
      }
    

    Thank You.



  • @jan_blaha @bjrmatos Hi , I've been noticed that whenever i send a request for PDF report there is a error

    ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'document' of null
    TypeError: Cannot read property 'document' of null
    

    and chrome alerts that pop-up is blocked .
    If i again send request then the another blank page will open which it will take min 10s to max 15s and the PDF will be shown .
    But it wont show any error nor the chrome alerts pop-up blocked.

    I've been using the above code only. Lemme know if any changes i have to be done or i may have skipped some steps , which will solve this issue.


  • administrators

    please see this topic https://forum.jsreport.net/topic/955/unable-to-download-csv-and-pdf-async/8, there i share how to show something when the popup is blocked, when the popup is blocked there is nothing else to do than showing some kind of message and ask the user to enable it


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.