/
web.js
39 lines (30 loc) · 859 Bytes
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Phantom JS script that generates a pdf from url
* Author: hugo.solar
*/
var page = require('webpage').create(),
system = require('system'),
address, output, size;
var url = system.args[1];
var width = system.args[3];
var height = '1200px';
var name = system.args[2];
page.paperSize = { width: width, height: height, margin: '15px' }
page.zoomFactor = 0.7;
page.open(url, function() {
page.render(name);
phantom.exit();
});
page.onLoadFinished = function(status) {
console.log('Status: ' + status);
};
page.onError = function(msg, trace) {
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
console.error(msgStack.join('\n'));
};