jsreport in amplify



  • jsreport looks like what I want to create statements in my amplify app. Is there any help to make this work? It's OK with me if the report isn't actually part of my app, although that would be preferable. I need to be able to load app data into a report template and have it render for the user who can then download it to PDF.

    Edit: I think I see one solution... use the API to the hosted report server for this purpose.



  • jsreport is a server-side solution, it won't run in browser or mobile at least for now.
    You need to host jsreport on a server (or use jsreport SaaS) and communicate with it through API.



  • OK, I have tried to follow the code you provide, but not really any luck yet. The screen prints

    report has run: {}

    If I debug the state.Report, it does show a PromiseState of "fulfilled"
    I couldn't find any example of using jsreport with Amplify NodeJS on the internet so I wrote this code.
    I think I'm missing some code and not sure how to write it.

    import React from "react";
    const client = require('jsreport-client')('http://localhost:5488/studio/templates/SJVbqZr9f')
    class RenderReport extends React.Component {

    componentDidMount() {
        var report = "";
        report = this.doRender();
        this.setState({Report: report});
      }
      doRender = async() => {
        try {
            async function renderReport () {
                const res = await client.render({
                    template: {
                    content: 'hello {{someText}}',
                    recipe: 'html',
                    engine: 'handlebars'
                    },
                    data: { someText: 'world!!' }
                })
                
                const bodyBuffer = await res.body()
                const report = bodyBuffer;
    
                // this will re render the view with new data
                return report;
    
                }
            }
            catch(err)
            {
                
                console.log(err);
                return(err);
            }
        }
    
        render() {
            if(this.state != undefined)
            {
            const reports = this.state.Report;
          
            return (
              <div>
           
                  <div>report has run: {JSON.stringify(this.state.Report)}</div>
    
              </div>
            );
            }
            else
            return(<div>report has not run</div>);
        }
    
    }
    export default RenderReport;


  • This looks like front-end browser code, so you should use jsreport browser client. The jsreport-client package is for node.js.


Log in to reply
 

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