doulan9287 2015-05-28 06:06
浏览 118
已采纳

如何延迟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.

  • 写回答

2条回答 默认 最新

  • douye8500 2015-05-28 12:42
    关注

    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..!!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?