I'm trying download my PDF file from jsreportonline



  • I'm trying download my PDF file from jsreportonline, but I can't because PDF doesn't convert and when I try open using bellow code I get an error of PDF format.

     jsreportClient.render(requestData).then(response => {
            this.$store.commit('setLoading', {
                show: false,
            });
            return response.body();
    }).then(response => {
        const linkSource = `data:application/pdf;base64,${response}`;
        const downloadLink = document.createElement("a");
        const fileName = "myfile.pdf";
    
        downloadLink.href = linkSource;
        downloadLink.download = fileName;
        downloadLink.click();
    });
    

  • administrators

    i think you are getting confused about the right sdk to use, it looks to me that you are trying to execute this in the browser but the code you are using looks like the node.js sdk which does not work in the browser, you need to use the browser sdk for this, we have an example here that includes some code to download the file.

    according to the browser sdk api your code should be like this:

    // somewhere before sending the request you need to configure that you want to use jsreport at specific url and credentials, in this case your jsreportonline url
    jsreport.serverUrl = 'https://your-account-name.jsreportonline.net/api/report'
    jsreport.headers['Authorization'] = "Basic " + btoa("youraccountname:youraccountpassword")
    
    jsreportClient.renderAsync(requestData).then(function(res) {
      this.$store.commit('setLoading', {
        show: false,
      });
     
      res.download('myfile.pdf')
    })
    


  • @bjrmatos I did it and it works fine. Thank you!

    But right now, I just have free 72 / 200 credits to use! :Do you know how I can ask more credits? Because these I used for tests, in this case, test with download that wasn't working.


  • administrators

    unfortunately, there is no way to reset the credits in this case. I understand that you were consuming the credits just for testing but this is the limitation of the free plan.

    if you want to test jsreport client integrations the best for you will be to start a jsreport locally just for your testing purposes (so you don't consume the credits of your account), then when you know that everything is working, you just need to update the serverUrl and Authorization to talk the the jsreportonline, basically two lines change and you avoid wasting the credits for testing purposes.



  • Yes! I got it.

    Thank you.


Log in to reply
 

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