Roby Sottini
Roby Sottini

Reputation: 2265

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.

Upvotes: 0

Views: 4857

Answers (2)

Jan Blaha
Jan Blaha

Reputation: 3095

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

Upvotes: 3

mirwaleed
mirwaleed

Reputation: 77

you can use html-pdf module for this https://www.npmjs.com/package/html-pdf

Upvotes: 1

Related Questions