PDF.js - 在嵌入式PDF上使用搜索功能 [英] PDF.js - Using search function on embedded PDF

查看:983
本文介绍了PDF.js - 在嵌入式PDF上使用搜索功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有 iframe src = viewer.html?file = ... 标记的PDF.js嵌入PDF。我正在使用PDF.js及其viewer.html,因为它已经提供了我在其他任何示例中都找不到的搜索功能。

I embedded a PDF using PDF.js with the iframe src=viewer.html?file=... tag. I'm using PDF.js and its viewer.html as it already provides a search function that I couldn't find in any other example.

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

I would like the user to be able to click on a <td> and use the containing text to search the PDF and jump to the first occurence. 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

JavaScript

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

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

I found similar questions on SO but they couldn't really answer my question:

  • 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

谢谢!

推荐答案

由于没有其他人回答我的问题,我将自己回答。
我终于使用viewer.html @ https:/ /github.com/mozilla/pdf.js/tree/master/web

As no one else responded to my question I'm going to answer it myself. I finally got it working by using the viewer.html @ https://github.com/mozilla/pdf.js/tree/master/web.

以下是我编写的一些示例代码,以使其正常工作。希望将来可以帮助其他人。

Here is some example code that I wrote to make it work. Hope it will help someone else in the future.

PDFView.open(pdf_url, 0);

// search with PDF.js
function searchPDF(td_text) {
    PDFView.findBar.open();
    $(PDFView.findBar.findField).val(td_text);
    $("#tableDiv").focus();

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

这篇关于PDF.js - 在嵌入式PDF上使用搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆