Getting a Blank PDF when Running Report Via Api.



  • Trying to get a reporting tool working, but when I get the report back from the API, I get only blank PDF's with no output. The page counts is correct, but it's not showing the report content in Acrobat.

    What could be the issue here?

    My code to request the Report is as follows:

      var options = { method: 'POST',
        url: 'http://192.168.100.64:5488/api/report',
        headers:
         { 'postman-token': '81e5ced9-d7b1-80bd-5948-a6934e67d4ae',
           'cache-control': 'no-cache',
           'content-type': 'application/json' },
        body:
         { template: { shortid: 'HJsjiZhob' },
           data:
            { Badges: badges },
           options: { 'Content-Disposition': 'Attachment; filename=badges.pdf' } },
        json: true };
    
      rq(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.dir(body);
        fs.writeFile(path.join(config.outFolder, 'badges.pdf'), body, 'binary', (err) => {
           if(err) log.error(err);
           log.info('Successfully Wrote Badge Sheet.');
         });
      });
    

    NOTE: var badges is defined/built prior to this code.


  • administrators

    hi! have you tried to do this?

    rq(options)
    .on('response', function (response) {
      console.log(response.statusCode) // 200
      console.log(response.headers['content-type'])
    })
    .on('error', function () {
      throw new Error(error);
    })
    .on('end', function () {
      log.info('Successfully Wrote Badge Sheet.');
    })
    .pipe(fs.createWriteStream(path.join(config.outFolder, 'badges.pdf'));
    

    jsreport response is sent in streaming, so handling it in this way should work and your pdf should have the right content



  • That sounds like a good idea let me try that out!



  • That works perfectly!

    Thank you!


  • administrators

    glad to help you!


Log in to reply
 

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