使用嵌入式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.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfefhe
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22