Created
April 25, 2014 13:21
-
-
Save oskarhane/11289359 to your computer and use it in GitHub Desktop.
Export any website to PDF. PhantomJS and node-phantom required.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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