How to use prawn pdf inside a node / express app

In a node.js app I want to generate pdf docs and send it back to the user. I would like to use Prawn PDF as I have used it before and am comfortable using it.

I suppose I should use node's child_process.spawn to call a ruby script (that returns a pdf) to achieve this but I do not know how to actually implement it!

Am doing this: spawn = require('child_process').spawn; pdf = spawn('my_ruby_script');

Now how do I get hold of the returned pdf doc?

Thanks, mano

I ended up with this eventually:

var spawn = require('child_process').spawn;
var child = spawn('ruby', ['print_pdf.rb', doc_id]);
var pdf = '';
child.on('data', function(data){
    pdf += data;
});
child.on('exit', function(code){
    if(code == 0){
        res.setHeader('Content-Type', 'application/pdf');
        res.send(pdf);
    }
});

The ruby prawn script generates the pdf and at the end just 'puts' the rendered pdf which is available to child as 'data'.