HTML to PDF with Node.js

I'm looking to create a printable pdf version of my website webpages. Something like express.render() only render the page as pdf

Does anyone know a node module that does that ?

If not, how would you go about implementing one ? I've seen some methods talk about using headless browser like phantom.js, but not sure whats the flow.

Extending upon Mustafa's answer.

Install http://phantomjs.org/ and then install the phantom node module https://github.com/sgentle/phantomjs-node

Here is an example of rendering a pdf

phantom = require('phantom')


phantom.create(function(ph){
  ph.createPage(function(page) {
    page.open("http://www.google.com", function(status) {
      page.render('google.pdf', function(){

        console.log('Page Rendered');
        ph.exit();

      });
    });
  });
});

Phantom.js is an headless webkit server and it will load any web page and render it in memory, although you might not be able to see it, there is a Screen Capture feature, in which you can export the current view as PNG, PDF, JPEG and GIF. Have a look at this example from phantom.js documentation

If you want to export HTML to PDF. You have many options. without node even

Option 1: Have a button on your html page that calls window.print() function. use the browsers native html to pdf. use media queries to make your html page look good on a pdf. and you also have the print before and after events that you can use to make changes to your page before print.

Option 2. htmltocanvas or rasterizeHTML. convert your html to canvas , then call toDataURL() on the canvas object to get the image . and use a JavaScript library like jsPDF to add that image to a PDF file. Disadvantage of this approach is that the pdf doesnt become editable. If you want data extracted from PDF, there is different ways for that.

Option 3. @Jozzhard answer