-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_phantomjs.js
More file actions
32 lines (31 loc) · 1.03 KB
/
script_phantomjs.js
File metadata and controls
32 lines (31 loc) · 1.03 KB
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
var url = 'https://ptosco.github.io/test_phantomjs.html';
var page = require('webpage').create();
page.viewportSize = { width: 600, height: 1080 };
page.paperSize = {
format: 'A3',
orientation: 'landscape',
margin: '20px'
};
page.settings.dpi = "300";
var interval = {
count: 0,
MAX_COUNT: 200
};
page.open(url, function() {
interval.id = setInterval(function() {
var content = page.content;
var isRenderingFinished = (typeof content === 'string'
&& content.indexOf('rect') !== -1
&& content.indexOf('div class="rdk-str-rnr-spinner" style="display: block;"') === -1);
if (isRenderingFinished || (++interval.count === interval.MAX_COUNT)) {
if (interval.id) {
clearInterval(interval.id);
}
if (!isRenderingFinished) {
console.log('Timeout before rendering was finished');
}
page.render('renderer.pdf', { format: 'pdf', quality: '100' });
phantom.exit();
}
}, 2000);
});