node.jspdfnpmpdf-generationjsreport

JSreport and Node.Js: how to generate a PDF file


I need to generate a PDF file in a Node.js server from HTML and CSS code.

I installed JSreport in a localhost Nginx server and it seems to do what I want: I enter to the web software, it receives HTML and CSS code and generate a PDF file.

Jsreport

Now the Node.js server receives some parameters (like person name) and then it have to call JSreport to generate the PDF file from a HTML file that I made.


Solution

  • If you want to run jsreport server in external process, you can use jsreport nodejs client to remotely render the pdf.

    var client = require("jsreport-client")(url, username, password)
    client.render({
        template: { content: "hello {{:someText}}", recipe: "html",
                    engine: "jsrender" },
        data: { someText: "world!!" }
    }, function(err, response) {
        response.body(function(body) {
            //prints hello world!!
            console.log(body.toString());
        });
    });
    

    See more in docs
    https://jsreport.net/learn/nodejs-client)

    Running jsreport and your app in the same node application is described also in docs here https://jsreport.net/learn/adapting-jsreport