Azure function and client js



  • Hello

    I followed the guide on setting up jsreport as an Azure function, and my template shows as expected on https://jsreporttest-abacus.azurewebsites.net/api/report

    Now I try to get it from the client, and I have tried both browser.js and node.js without any luck.
    browser.js

         const jsreport = require('jsreport-browser-client-dist')
         jsreport.serverUrl = "https://jsreporttest-abacus.azurewebsites.net";
    
         var request = {
            template: {
              shortid: 'oizlGafQAt', recipe: 'chrome-pdf'
            },
            data : {
              to: "To",
              from: "From",
              price:"200"
            }
          };
    
           jsreport.render('_blank', request);
    

    This gives the error in the browser: "Template must contains _id, shortid or content attribute.....(stacktrace)" (I have tried to use content instead of shortid as well, but still the same error)

    node.js

          const jsreport = require("jsreport-client")("https://jsreporttest-abacus.azurewebsites.net");
    
          const res = await jsreport.render({
            template: {
             shortid: 'oizlGafQAt',
              recipe: 'html',
              engine: 'handlebars'
            },
            data : {
              to: "To",
              from: "From",
              price:"200"
            }
          })
         const bodyBuffer = await res.body()
         console.log(bodyBuffer.toString())    
    

    Gives the error in the console: "XML Parsing Error: junk after document element" (but I se in the Network tab that it actually generates the HTML in the response correctly) If I switch to receipe: chrome-pdf it gives : "XML Parsing Error: not well-formed"

    What am I doing wrong here?



  • I believe you followed this tutorial?
    https://jsreport.net/learn/azure-functions-serverless

    In this case, the nodejs or browser jsreport client isn't compatible with the lambda function.
    The lambda function returns base64 encoded data which you need to decode on the client side.
    See in the example how you can make the request and download the output.
    https://github.com/jsreport/jsreport-azure-functions-starter-kit/blob/master/test.js



  • Thanks, yes I followed that one.

    I will look into it tomorrow. Guess I can use the code sample until the fs.createWriteStream part, because that wont be possible in the browser/client...



  • Can't figure out what to do with the base64 encoded data. Found this related thread, and I have tried the same actions, but I get the same result as that user. Any suggestions on how to get the pdf from this base64 encoded format to a downloadable PDF?


Log in to reply
 

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