| 1 | "use strict"; |
| 2 | var page = require('webpage').create(), |
| 3 | system = require('system'); |
| 4 | |
| 5 | if (system.args.length < 7) { |
| 6 | console.log('Usage: printmargins.js URL filename LEFT TOP RIGHT BOTTOM'); |
| 7 | console.log(' margin examples: "1cm", "10px", "7mm", "5in"'); |
| 8 | phantom.exit(1); |
| 9 | } else { |
| 10 | var address = system.args[1]; |
| 11 | var output = system.args[2]; |
| 12 | var marginLeft = system.args[3]; |
| 13 | var marginTop = system.args[4]; |
| 14 | var marginRight = system.args[5]; |
| 15 | var marginBottom = system.args[6]; |
| 16 | page.viewportSize = { width: 600, height: 600 }; |
| 17 | page.paperSize = { |
| 18 | format: 'A4', |
| 19 | margin: { |
| 20 | left: marginLeft, |
| 21 | top: marginTop, |
| 22 | right: marginRight, |
| 23 | bottom: marginBottom |
| 24 | } |
| 25 | }; |
| 26 | page.open(address, function (status) { |
| 27 | if (status !== 'success') { |
| 28 | console.log('Unable to load the address!'); |
| 29 | } else { |
| 30 | window.setTimeout(function () { |
| 31 | page.render(output); |
| 32 | phantom.exit(); |
| 33 | }, 200); |
| 34 | } |
| 35 | }); |
| 36 | } |