Created
April 19, 2012 13:01
-
-
Save atheken/2420835 to your computer and use it in GitHub Desktop.
more rasters
This file contains hidden or 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
var fs = require('fs'); | |
var page = require('webpage').create(), | |
address, | |
output, | |
size; | |
if (phantom.args.length < 2 || phantom.args.length > 3) { | |
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'); | |
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); | |
phantom.exit(); | |
} else { | |
address = phantom.args[0]; | |
output = phantom.args[1]; | |
//page.viewportSize = { width: 600, height: }; | |
page.settings.userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'; | |
page.settings.loadPlugins = false; | |
if (phantom.args.length === 3 && phantom.args[1].substr( - 4) === ".pdf") { | |
size = phantom.args[2].split('*'); | |
page.paperSize = size.length === 2 ? { | |
width: size[0], | |
height: size[1], | |
border: '0px' | |
} | |
: { | |
format: phantom.args[2], | |
orientation: 'portrait', | |
border: '0in' | |
}; | |
} | |
//page.viewportSize = { width: 600, height: 600 }; | |
page.open(address, | |
function(status) { | |
if (status === 'success') { | |
page.clipRect = page.evaluate(function() { | |
return document.querySelector("html").getBoundingClientRect(); | |
}); | |
console.log(page.clipRect.top, page.clipRect.left, page.clipRect.width, page.clipRect.height); | |
page.render(output); | |
phantom.exit(); | |
} else { | |
console.log("Page didn't load properly."); | |
phantom.exit(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment