rc-web@12: var page = require('webpage').create(), rc-web@12: system = require('system'), rc-web@12: address, output, size; rc-web@12: rc-web@26: top = system.args[3]; rc-web@26: rc-web@43: page.clipRect = { top: top, left: 0, width: 1000, height: 330 } rc-web@12: rc-web@12: if (system.args.length < 3 || system.args.length > 5) { rc-web@12: console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); rc-web@12: console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); rc-web@12: phantom.exit(1); rc-web@12: } else { rc-web@12: address = system.args[1]; rc-web@12: output = system.args[2]; rc-web@26: rc-web@26: rc-web@43: page.viewportSize = { width: 1000, height: 330 }; rc-web@26: if (system.args.length > 4 && system.args[2].substr(-4) === ".pdf") { rc-web@26: size = system.args[4].split('*'); rc-web@12: page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' } rc-web@32: : { format: system.args[3], orientation: 'portrait', margin: '0cm' }; rc-web@12: } rc-web@26: if (system.args.length > 5) { rc-web@26: page.zoomFactor = system.args[5]; rc-web@12: } rc-web@12: page.open(address, function (status) { rc-web@12: if (status !== 'success') { rc-web@12: console.log('Unable to load the address!'); rc-web@12: } else { rc-web@12: window.setTimeout(function () { rc-web@12: page.render(output); rc-web@12: phantom.exit(); rc-web@12: }, 200); rc-web@12: } rc-web@12: }); rc-web@12: }