PDF.js - Using search function on embedded PDF

前端 未结 4 537
野趣味
野趣味 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:02

    As no one else responded to my question I'm going to answer it myself. I finally got it working by using the viewer.html @ https://github.com/mozilla/pdf.js/tree/master/web.

    Here is some example code that I wrote to make it work. Hope it will help someone else in the future.

    PDFView.open(pdf_url, 0);
    
    // search with PDF.js
    function searchPDF(td_text) {
        PDFView.findBar.open();
        $(PDFView.findBar.findField).val(td_text);
        $("#tableDiv").focus();
    
        var event = document.createEvent('CustomEvent');
        event.initCustomEvent('find', true, true, {
            query: td_text,
            caseSensitive: $("#findMatchCase").prop('checked'),
            highlightAll: $("#findHighlightAll").prop('checked'),
            findPrevious: undefined
        });
        return event;
    }
    

提交回复
热议问题