Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
REMitchell
GitHub Repository: REMitchell/python-crawling
Path: blob/master/6-Selenium/phantomjs/examples/printmargins.js
164 views
1
var page = require('webpage').create(),
2
system = require('system');
3
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
}
36
37