jquery – PDF.js – 在嵌入式PDF上使用搜索功能

前端之家收集整理的这篇文章主要介绍了jquery – PDF.js – 在嵌入式PDF上使用搜索功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用带有iframe src = viewer.html?file = …标签的PDF.js嵌入了PDF.我正在使用PDF.js及其viewer.html,因为它已经提供了我在其他任何示例中都找不到的搜索功能.

我希望用户能够点击< td>并使用包含文本搜索PDF并跳转到第一次出现. JSFiddle:http://jsfiddle.net/agyetcsj/

HTML

<div id="tableDiv"><table border="1" width="400px"><tr><td>6.5  Calling External Functions</td></tr></table></div>
<iframe id="pdfImage" width="600px" height="600px" class="pdf" src="http://mozilla.github.com/pdf.js/web/viewer.html?file=compressed.tracemonkey-pldi-09.pdf"></iframe>

JavaScript的

$('td').unbind('click').click(function () {
    alert("Find text in PDF!");
});

我在SO上发现了类似的问题,但他们无法真正回答我的问题:

> https://stackoverflow.com/questions/24439701/searching-embedded-pdfs-in-iframes
> https://stackoverflow.com/questions/28322082/sencha-search-text-in-pdf-file-rendered-from-plugin-pdf-js
> Access PDF.js Viewer functions / events

谢谢!

解决方法

受dev-random的回答启发,我将以下代码添加到viewer.js.我通过传递url参数打开我的pdf,例如 http://localhost:3000/pdf/viewer.html?&search=your_search_term.这样,当您打开PDF文件时,将自动执行适合我的用例的搜索.
//Add this piece of code to webViewerInitialized function in viewer.js
if ('search' in params) {
    searchPDF(params['search']);
}

//New function in viewer.js
function searchPDF(td_text) {
    PDFViewerApplication.findBar.open();
    PDFViewerApplication.findBar.findField.value = td_text;
    PDFViewerApplication.findBar.caseSensitive.checked = true;
    PDFViewerApplication.findBar.highlightAll.checked = true;
    PDFViewerApplication.findBar.findNextButton.click();
    PDFViewerApplication.findBar.close();
}
原文链接:https://www.f2er.com/jquery/175742.html

猜你在找的jQuery相关文章