Can i send the template as HTML as string with my own design .



  • Hi Team, Good day.

    In this Post i want to clarify that Can i send the data like given below to the jsreport starter kit which is used for lambda based configurations REFERENCE LINK: https://jsreport.net/learn/aws-lambda-serverless

    Sample JSON request:

    {
        "renderRequest": {
            "template": {
                "content":`
    \n' +
    '<html lang="en">\n' +
    '\n' +
    '<head>\n' +
    '  <meta charset="UTF-8">\n' +
    '  <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
    '  <title>My Website</title>\n' +
    '\n' +
    '</head>\n' +
    '\n' +
    '<body>\n' +
    '\n' + // Added an empty line before your content area
    
    '  <header>\n' +
    '    <h1>Welcome to My Website</h1>\n' +
    '  </header>\n' +
    '\n' +
    
    '  <main>\n' +
    '    <h2>Example Table</h2>\n' +
    '    <table>\n' +
    '      <tr>\n' +
    '        <th>Name</th>\n' +
    '        <th>Age</th>\n' +
    '        <th>City</th>\n' +
    '      </tr>\n' +
    '      <tr>\n' +
    '        <td>John Doe</td>\n' +
    '        <td>30</td>\n' +
    '        <td>New York</td>\n' +
    '      </tr>\n' +
    '      <tr>\n' +
    '        <td>Jane Smith</td>\n' +
    '        <td>25</td>\n' +
    '        <td>London</td>\n' +
    '      </tr>\n' +
    '    </table>\n' +
    '  </main>\n' +
    '\n' +
    
    '  <footer>\n' +
    '    <p>&copy; 2024 My Website</p>\n' +
    '  </footer>\n' +
    '\n' +  
    '</body>\n' +
    '\n' +
    '</html>\n'
    `
    `;
    ,
                "engine": "handlebars",
                "recipe": "chrome-pdf",
                "chrome": {
                    "format": "A4",
                    "orientation": "portrait",
                    "fittopage": true,
                    "margin": {
                        "top": "30px",
                        "left": "20px",
                        "right": "20px",
                        "bottom": "10px"
                    }
                },
                "helpers": " function myFunction (x){return x}"
            }
        }
    }
    

    In lambda actual jsreport npm packages not working. So i tried this way to implement the actual jsreport functionality in lambda based.

    I will send the Request like given above. Kindly confirm whether this is right approach or not. Kindly guide me to get this done.

    Thanks in advance



  • I configured this in Lambda function and i got the Functional URL aswell.
    I need to use this service by calling this form Node Project.

    Consider i have my templates and data and rest of the parameters.

    How can i call this In my nodeJs and being served by lambda.



  • Here is the code in node invoking the lambda
    https://github.com/jsreport/jsreport-aws-lambda-starter-kit/blob/master/test.js

    I'm not sure I understand you fully, but you can of course render a template fully specified in the request as you do. It is the same as calling jsreport API.



  • Hi Admin,

    Thanks for your reply.
    I followed the same. templates with helpers, content, engine, recipe, chrome are fine. For my template i need to pass the set of data as Json , How can i send the data to that function .
    below is the code implementation

    const requestBody=event.renderRequest
    const resp = await jsreport.render(requestBody);

    in requestBody will contain below data

    {
    template: {
    content: "Hey Buddy this is called from the backend you know",
    engine: "handlebars",
    recipe: "chrome-pdf",
    chrome: {
    format: "A4",
    orientation: "portrait",
    fittopage: true,
    margin: {
    top: "30px",
    left: "20px",
    right: "20px",
    bottom: "10px",
    },
    },
    helpers: "function myFunction (x){return x}",
    }
    datas:[{temp1:"temp1Data"},{temp2:"temp2Data"}]}
    }

    Because these datas needs to be bind with my template.

    Kindly check above and guide me to close this .

    Thanks.



  • Its same as the API call
    https://jsreport.net/learn/api

       {
          "template": { ... },
          "data" : { ... },    
       }
    


  • Hi Admin,

    Thanks for the insights.

    It's working as expected.

    Will explore more on it and let you know any issue we face in future.


Log in to reply
 

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