简体   繁体   English

错误。在iFrame中访问PDF元素

[英]ERROR.Access PDF element inside iFrame

I am trying to search for a word inside a pdf using a textbox inside the webpage.I embedded the pdf inside a IFRAME, but it is not working.This code is working with normal text.When i search for words, sometimes it opens the pdf or refreshes the page, instead of highlighting it. 我正在尝试使用网页内的文本框在pdf中搜索单词。我将pdf嵌入到IFRAME中,但是它不起作用。此代码适用于普通文本。当我搜索单词时,有时会打开pdf或刷新页面,而不是突出显示页面。

    <style>
      span.highlight {
  background: yellow
}
        </style>
        <input type="text" />
        <div class="para">
        <button onclick="getIframeText()">get iframe text</button>
        <iframe id="myframe1" src="h.pdf" style="width:718px; height:700px;" frameborder="0"></iframe>

    </div>

JAVASCRIPT FOR SEACRHING THE TEXT JAVASCRIPT用于搜索文本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   <script type='text/javascript'>
 var $para = $('.para')
$("input").keyup(function() {
  $para.find('span.highlight').contents().unwrap();
  var mysearchword = this.value.trim();
  if (mysearchword) {
    var re = new RegExp('(' + mysearchword.trim().split(/\s+/).join('|') + ')', "gi");
    $para.html(function(i, html) {
      return html.replace(re, '<span class="highlight">$1</span>')
    });
  }
});
</script>

The code will not work for PDF. 该代码不适用于PDF。

Replacing the word found in HTML with highlight class, it's okay. highlight类替换HTML中找到的单词,没关系。 But this is not possible for PDF. 但这对于PDF是不可能的。 You need to convert PDF into HTML first. 您需要先将PDF转换为HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM