Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在嵌入式PDFJS上使用代码进行搜索_Javascript_Php_Pdf_Pdfjs - Fatal编程技术网

Javascript 在嵌入式PDFJS上使用代码进行搜索

Javascript 在嵌入式PDFJS上使用代码进行搜索,javascript,php,pdf,pdfjs,Javascript,Php,Pdf,Pdfjs,我已将PDFJS与我的网页集成。我想使用javascript进行搜索 它在第一次搜索时运行良好。但我尝试用不同的关键字再次搜索,结果没有突出显示正确的关键字 以下是我尝试过的: // search with PDF.js function searchPDF(td_text) { PDFViewerApplication.findBar.open(); PDFViewerApplication.findBar.findField.value

我已将
PDFJS
与我的网页集成。我想使用javascript进行搜索

它在第一次搜索时运行良好。但我尝试用不同的关键字再次搜索,结果没有突出显示正确的关键字

以下是我尝试过的:

    // search with PDF.js
    function searchPDF(td_text)
    {
        PDFViewerApplication.findBar.open();
        PDFViewerApplication.findBar.findField.value = td_text;
        PDFViewerApplication.findBar.highlightAll.checked= true;
        PDFViewerApplication.findBar.findNextButton.click();
    }


    function resetPDFSearch()
    {
        if(PDFViewerApplication.findBar.findField.value != '') {
            PDFViewerApplication.findBar.findField.value = '';
            PDFViewerApplication.findBar.highlightAll.checked= false;
            PDFViewerApplication.findController.reset();
            PDFViewerApplication.findBar.close();
            PDFViewerApplication.findController.matchCount = 0;
            PDFViewerApplication.findController.updateMatch();
        }
    }
在上面的函数中,当我第一次调用
searchPDF()
时,关键字会正确高亮显示。但同样,如果我用不同的关键字调用同一个函数,那么它只显示先前高亮显示的关键字

我尝试创建新函数
resetPDFSearch()
,以重置所有以前筛选和突出显示的关键字。但是没有运气


提前谢谢。

在经历了这么多头痛和头脑风暴之后。我的回答如下

function searchPDF(td_text)
{
    PDFView.findBar.open();
    $(PDFView.findBar.findField).val(td_text);

    var event = document.createEvent('CustomEvent');
    event.initCustomEvent('findagain', true, true, {
        query: td_text,
        caseSensitive: $("#findMatchCase").prop('checked'),
        highlightAll: $("#findHighlightAll").prop('checked', true),
        findPrevious: undefined
    });

    PDFViewerApplication.findBar.dispatchEvent('');

    return event;
}
无需使用
resetPDFSearch()
函数

本案例适用于我的场景。希望你有不同的情况。但是可以使用
事件
搜索任意时间。:)


在经历了如此多的头痛和头脑风暴后,可能对将来的某个人有所帮助。

。我的回答如下

function searchPDF(td_text)
{
    PDFView.findBar.open();
    $(PDFView.findBar.findField).val(td_text);

    var event = document.createEvent('CustomEvent');
    event.initCustomEvent('findagain', true, true, {
        query: td_text,
        caseSensitive: $("#findMatchCase").prop('checked'),
        highlightAll: $("#findHighlightAll").prop('checked', true),
        findPrevious: undefined
    });

    PDFViewerApplication.findBar.dispatchEvent('');

    return event;
}
无需使用
resetPDFSearch()
函数

本案例适用于我的场景。希望你有不同的情况。但是可以使用
事件
搜索任意时间。:)


可能对将来的人有帮助。

对于那些使用pdf.viewer.js的人,这里有另一个解决方案:

// this method uses the viewers search funtionality to highligt given text
function searchText(txt) {

    if (typeof PDFViewerApplication.findController !== 'undefined') {
        PDFViewerApplication.findController.executeCommand('find', {
            query: txt,
            caseSensitive: false,
            highlightAll: true,
            findPrevious: true
        });
    }

}

对于那些使用pdf.viewer.js的用户,这里有另一个解决方案:

// this method uses the viewers search funtionality to highligt given text
function searchText(txt) {

    if (typeof PDFViewerApplication.findController !== 'undefined') {
        PDFViewerApplication.findController.executeCommand('find', {
            query: txt,
            caseSensitive: false,
            highlightAll: true,
            findPrevious: true
        });
    }

}

我需要类似的东西。我的框架也实现了pdf.viewer.js。请问什么是
PDFViewerApplication
?@codyLine PDFViewerApplication是一个对象,它包含pdf视图的参数。我如何访问它?您的代码警告我全局变量
PDFViewerApplication
未声明@codyLine请检查pdfviewer的存储库。这是一个例子:我需要类似的东西。我的框架也实现了pdf.viewer.js。请问什么是
PDFViewerApplication
?@codyLine PDFViewerApplication是一个对象,它包含pdf视图的参数。我如何访问它?您的代码警告我全局变量
PDFViewerApplication
未声明@codyLine请检查pdfviewer的存储库。以下是示例: