printmargins.js 1.0 KB

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