Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Option wait for image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
6uimorais committed May 5, 2018
1 parent f723ff3 commit 53e7ec2
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions lib/phantom-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var cmdArgs = ["htmlPath",
"paperWidth",
"paperHeight",
"renderDelay",
"runningsArgs"];
"runningsArgs",
"waitImgLoading"];

args = cmdArgs.reduce(function (args, name, i) {
args[name] = system.args[i + 1];
Expand Down Expand Up @@ -74,13 +75,36 @@ page.open(skeleton, function (status) {
page.paperSize = paperSize(runnings, defaultFormat);
}

/* Render the page */
setTimeout(function () {
page.render(args.pdfPath);
page.close();
phantom.exit(0);
}, parseInt(args.renderDelay, 10));
if(args.waitImgLoading) {

setInterval( function() {

pendingImages = page.evaluate(function() {
var images = document.images;
for (var i = 0; i < images.length; i++) {
if (!images[i].complete) {
return images[i].src;
}
}
return false
});

if(pendingImages) { return }
page.render(args.pdfPath);
page.close();
phantom.exit(0);

}, parseInt(args.renderDelay, 10));


} else {
/* Render the page */
setTimeout(function () {
page.render(args.pdfPath);
page.close();
phantom.exit(0);
}, parseInt(args.renderDelay, 10));
}
});

function paperSize(runnings, obj) {
Expand Down

0 comments on commit 53e7ec2

Please sign in to comment.