• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

用户头像
it1352
帮助1

问题说明

我已经将PDFJS与我的网页集成在一起.我想使用JavaScript进行搜索.

I have integrated PDFJS with my webpage. I want to search using javascript.

对于首次搜索来说效果很好.但是,然后我尝试再次使用其他关键字进行搜索,然后它没有突出显示正确的关键字.

It's working fine for first time search. But then I try to search again with different keyword then it's not highlighting proper keyword.

这是我尝试过的:

    // 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()时,关键字正确突出显示.但是,如果我使用不同的关键字调用相同的函数,那么它将仅显示以前突出显示的关键字.

In above function, when I call searchPDF() first time then keyword is highlighting properly. But again if I call same function with different keyword then it shows previously highlighted keyword only.

我尝试创建新功能resetPDFSearch()来重置所有先前过滤并突出显示的关键字.但没有运气.

I try to create new function resetPDFSearch() to reset all previously filtered and highlighted keywords. But no luck.

谢谢.

正确答案

#1

经过如此多的头痛和头脑风暴.我来回答如下.

After so much headache and brainstorming. I come to answer as below.

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()功能.

这种情况适用于我的情况.希望你有不同的情况.但是,是的,使用event,我可以根据需要搜索尽可能多的时间. :)

This case is for my scenario. Hope you might have different case. But yes using event I can search as many time as I want. :)

将来可能会对某人有所帮助.

Might be helpful to someone in future.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfefhe
系列文章
更多 icon
同类精品
更多 icon
继续加载