BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / phantomjs-prebuilt / lib / phantom / examples / printmargins.js

printmargins.js

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
printmargins.js 1.0 KiB Download Raw
1"use strict";
2var page = require('webpage').create(),
3 system = require('system');
4
5if (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}