Skip to content

Instantly share code, notes, and snippets.

@athibaud
Last active August 29, 2015 14:14
Show Gist options
  • Save athibaud/c7bd4809baaf5cc11e19 to your computer and use it in GitHub Desktop.
Save athibaud/c7bd4809baaf5cc11e19 to your computer and use it in GitHub Desktop.
'use strict';
var page = require('webpage').create();
var system = require('system');
var address;
var output;
if (system.args.length < 3) {
console.log('Usage: rasterize.js [URL|filepath] filename');
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
var pageWidth = '148mm';
var pageHeight = '210mm';
page.paperSize = {
width: pageWidth,
height: pageHeight,
margin: 0
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment