PDF generation with PhantomJS in node-Webkit

I found a comment in this subject node wkhtmltopdf create corrupted PDF in node webkit which indicates that it's possible to generate pdf from html in node-webkit by using PhantomJS and especially with this script: https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js

However I don't understand how to use this script without command line call...

It's not possible to use the script as-is directly in node.js. You would either use the child_process module to call phantomjs essentially as a commandline script with the rasterize.js script and options.

The other possibility is to use a phantom wrapper for node.js to directly include the code of rasterize.js. You would need to make only small adjustments like the page argument is passed from the wrapper and does not need to be created. Possible wrappers are node-phantom or phantomjs-node. If you package your app with node-webkit, then you will probably run into problems with the path to the phantomjs executable.

Phantomjs' Rasterize.js worked well to generate clean multi-page editable pdf's conserving all the tricky CSS. I got a little confused when trying to use it within a nodejs environment but its pretty straight forward.

As per NPM Phantomjs readme: (I've stated it a little more explicitly)

var path = require('path')
var childProcess = require('child_process')
var phantomjs = require('phantomjs')
var binPath = phantomjs.path

//Args for rasterize.js: [ rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]') ]

var childArgs = [ path.join(__dirname, 'rasterize.js'),'url','docname.pdf','A4',1.00]

childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
  // handle results
})