如何延迟pdf扫描,直到页面加载完全pdfcrowd api在PHP?

I am using pdfcrowd API for generating PDF from my dynamic PHP webpage, in which I am getting some data from DB and also running some jQuery functions with setTimeout function having 2 to 3 seconds delay at the bottom of page inside document ready function of jQuery.

This jQuery functions I am using to set page layout height dynamically based on content using Lightweight Responsive jQuery - Waterfall plugin, which takes some time to do that.

So, when I try to download PDF, it downloads page without running my JavaScript/jQuery function, which delay approx 2 to 3 second in it.

Code detail that I am using:

MyWebPage Code looks something like this:

//HTML + PHP code here at top of page

//jQuery code to set page height dynamically

function setContainerHeight(containerDiv) {
 //function code here..
}
$(document).ready(function() {
    setTimeout(
        function() {
            $(containerDiv).waterfall({gridWidth:[0,500,1000,1500,2000],gap:10});
            setTimeout(function() {setContainerHeight(containerDiv);},2000);
        },1000
    );
});

Download Page

$client->setPageLayout(Pdfcrowd::CONTINUOUS); 
$pdf = $client->convertURI($myWebPageUrl);

// Set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"Resume.pdf\"");
// send the generated PDF 
echo $pdf;

Please help me in this, how I can delay the PDF scan until my page loads completely.

Thanks in advance.

Since you can't hold webpage to render, as your JavaScript function is running after page load as usingsetTimeout, you should do whatever is required with page load only.

So, You should try calling your function setContainerHeight() after plugin work completion, means you should try call back function of plugin.

And remember to remove setTimeout as they will not be required, after using callback function. Moreover, if your plugin doesn't have callback, so you should mind calling your function from plugin file, though this is not correct way, but it should do the trick.

In your case, you should search for function named sorting in your waterfall API and add your function call in last of it.

Hopefully, this helps you..!!!

Your question does not clarify what the problem really is, may be a problem of the javascript not knowing when the PDF file has loaded fully, can you call it by an ajax call? If you are loading the PDF to an IFrame you could try this:

$("#iFrameId").on("load", function () {
    $(containerDiv).waterfall({gridWidth:[0,500,1000,1500,2000],gap:10});
});

If the problem is in php, may be the output of the PDF beeing slowed by the api you could stop the output buffer until the process is done by:

ob_start(); //at the begining
//Your code until echo
ob_end_flush(); //at the end