使用嵌入式PDFJS上的代码进行搜索 [英] Search using code on Embedded PDFJS
问题描述
我已经将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.
谢谢.
推荐答案
经过如此多的头痛和头脑风暴.我来回答如下.
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.
这篇关于使用嵌入式PDFJS上的代码进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!