nextJS via jsreport-client render/embed pdf on page to preview



  • I am implementing jsreport-client on a nextJS app
    created a custom API handler that goes out and creates a PDF
    When I call this API handler it downloads a pdf to the client
    How do I instead render the response to be embedded/previewed on a browser?

    Here is the code:

    
    const client = require("jsreport-client")("https://BBB.jsreportonline.net/", "admin", "pass")
    
    async function render(req) {
        try {
    
            const rendered = await client.render({
                "template": {
                    "content": "Hello world {{name}}",
                    "recipe": "chrome-pdf",
                    "engine": "handlebars",
                    "chrome": {
                        "landscape": true
                    }
                },
                "data": { "name": "hello" }
            })
            const bodyBuffer = await rendered.body()
    
            return bodyBuffer;
        } catch (error) {
            debugger;
            return "error";
        }
    
    }
    
    
    
    export default async (req, res) => {
        const rendered = await render();
        res.statusCode = 200;
        res.send(rendered);
    }

Log in to reply
 

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