<repo_name>iamawwsome/phantomjs-html-pdf<file_sep>/html-to-pdf.js
const webpage = require('webpage');
const system = require('system');
const args = system.args;

const input = args[1];
const output = args[2];


if (!output) {
  throw new Error('Missing output args.');
}

const page = webpage.create();

page.open(input, function() {
  page.paperSize = {
    width: '8.5in',
    height: '11in',
    header: {
      height: '1cm',
      contents: phantom.callback(function(pageNum, numPages) {
        return ('<h1 style="font-size: 12px">' + page.title + '<span style="float:right">' + pageNum + ' / ' + numPages + '</span></h1>');
      })
    },
    footer: {
      height: '1cm',
      contents: phantom.callback(function(pageNum, numPages) {
        return ('<h1 style="font-size: 12px">' + page.title + '<span style="float:right">' + pageNum + ' / ' + numPages + '</span></h1>');
      }),
    },
  };

  page.render(output);
  phantom.exit();
});
<file_sep>/README.md
## PhantomJS: HTML to PDF

This is an example on how to create an API service, using PhantomJS, to generate PDF documents from webpages.

### Prerequisites

- NodeJS 6+
- Yarn 1.3+
- NPM 5+

Download the PhantomJS binary at http://phantomjs.org/download.html and place the executable in this project's bin directory.

```
yarn install && node index.js
```

The example php website should be accessible at http://localhost:3000
