PDF.js - Using search function on embedded PDF

前端 未结 4 542
野趣味
野趣味 2020-12-16 19:51

I embedded a PDF using PDF.js with the iframe src=viewer.html?file=... tag. I\'m using PDF.js and its viewer.html as it already provides a search function that

4条回答
  •  伪装坚强ぢ
    2020-12-16 20:04

    I tried to implement @webstruck's approach but couldn't resolve "PDFView is not defined" error. I end up resolving like this:

    //Add this piece of code to webViewerInitialized function in viewer.js
    if ('search' in params) {
        searchPDF(params['search']);
    }
    

    then changed his approach to this:

    //New function in viewer.js
    function searchPDF(p_search_text) {
       var l_params = { query: p_search_text, phraseSearch: p_search_text };
       webViewerFindFromUrlHash(l_params);
    }
    

    In the HTML the iframe I added the &search=term and got like this:

    
    

    Worked like a charm, all words highlighted!

提交回复
热议问题