Skip to content

Instantly share code, notes, and snippets.

@oskarhane
Created April 25, 2014 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskarhane/11289359 to your computer and use it in GitHub Desktop.
Save oskarhane/11289359 to your computer and use it in GitHub Desktop.
Export any website to PDF. PhantomJS and node-phantom required.
phantom = require('phantom')
if(!process.argv[2]) {
console.log('Usage: node app.js [url]')
process.exit(1)
}
var url = process.argv[2]
phantom.create(function(ph){
ph.createPage(function(page) {
page.set('paperSize', {
format: 'A4'
})
page.open(url, function(status) {
page.render(url.replace(/https?:\/\//g, '') + '.pdf', function(){
console.log('Page Rendered')
ph.exit()
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment