简体   繁体   中英

How to detect when documentViewer finish loading all document pages?

I am using primefaces documentViewer which is based on mozilla PDF.js: 2.11.338

https://www.primefaces.org/showcase-ext/views/documentViewer.jsf

and I want to know How to detect when documentViewer finish loading all document pages?

The requirement is to show loading bar until all the document pages finish loading.

I tried this:

document.addEventListener('textlayerrendered', function (e) {
    if (e.detail.pageNumber === PDFViewerApplication.page) {
        // finished rendering
    }
}, true);

and it's not working.

I was able to make it work as follows:

window.onload = function(){
         
        PF('statusDialog').show();
         var checkExist = setInterval(function() {
                var iframe=document.getElementsByTagName('iframe')[0];
               var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
                var viewer = innerDoc.getElementById('viewer');
                var innerHTML = viewer.innerHTML;
                if(innerHTML != null && innerHTML!='' && innerHTML!='undefined'){
                    clearInterval(checkExist);
                    PF('statusDialog').hide();
                }              
          }, 1000);  
        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM