繁体   English   中英

如何在PDFObject中使用搜索功能?

[英]How to use the search feature in PDFObject?

我正在使用PDFObject尝试搜索PDF中的某个术语并将其突出显示。 该网站实际上会自动为此类应用程序生成代码,但由于某种原因,该代码实际上根本没有在搜索我的PDF,也没有突出显示我要突出显示的单词...有人知道我该怎么做或纠正我的问题吗?码?

这是网站自动为我生成的代码(HTML):

    <!-- insert in the document body -->

<object data='sample#search=location&highlight=20,20,20,20' 
        type='application/pdf' 
        width='100%' 
        height='100%'>

<p>It appears your Web browser is not configured to display PDF files. 
No worries, just <a href='sample'>click here to download the PDF file.</a></p>

</object>

我想在PDF对象中找到(并突出显示)的搜索词是一个叫做“位置”的词。

我已将此代码复制到我的总体HTML代码中,如下所示:

    <html>
    <head>
     <title>PDFObject Example</title>
     <script type="text/javascript" src="pdfobject.js"></script>
     <script type="text/javascript">
      window.onload = function (){
        var myPDF = new PDFObject({ url: "sample.pdf" }).embed();
      };
    </script>
  </head>
  <body>
      <object data='sample.pdf#search=location&highlight=20,20,20,20' 
              type='application/pdf' 
              width='100%' 
              height='100%'>

      <p>It appears your Web browser is not configured to display PDF files. 
      No worries, just <a href='sample.pdf'>click here to download the PDF file.</a></p>
</body>
      </object>
</html>

提前致谢!


更新 (7/13)

Pipwerks提供的代码可以完美运行,谢谢。 我还有一个问题。 我使用“此”代码(见下文)为搜索词添加了突出显示,但是当我搜索一个词时,突出显示本身不会自动显示; 任何想法如何解决? 因此,从本质上讲,当在Acrobat中打开PDF时,搜索功能运行良好,并且在左侧菜单窗格中,我可以看到搜索结果。 但是,我正在搜索的术语在加载PDF时不会自动在屏幕上突出显示; 是否有必要进行设置,以便在加载PDF时突出显示我要搜索的术语?

 <html>
  <head>
     <script type="text/javascript" src="pdfobject.js"></script>
     <script type='text/javascript'>

       function embedPDF(){

         var myPDF = new PDFObject({ 

           url: 'sample.pdf',
           pdfOpenParams: { search: 'B27-1', highlight: '30,30,30,10' }

         }).embed();  

       }

       window.onload = embedPDF; //Feel free to replace window.onload if needed.

     </script>
  </head>
      </object>
</html>

是index.html时PDF当前的外观(搜索功能正常运行,但默认情况下未突出显示我的用语)。

这里就是我想要的PDF看起来像在加载时的index.html; 如果您实际上单击了搜索词,则会出现一个高亮框(如图中所示)。 我希望该高亮框随我想在地图上找到的任何搜索词一起加载PDF。

任何帮助将不胜感激,您确实是救生员Pipwerks,感谢您的帮助!

不幸的是, PDF Open Parameters是特定于Adobe的,不适用于大多数PDF阅读器,包括Chrome和Firefox中的内置PDF查看器。 实际上,近五年来,这一直是Google Chromium项目中的一个问题/功能请求

在Adobe Reader中对您有用吗?

-更新-

重新阅读您的帖子,您的代码不正确。 您混合使用了static和JavaScript选项-您需要选择其中一个。 如您所写,您的JavaScript(不包括搜索参数)将覆盖您的HTML版本。

JavaScript方法:

<html>
<head>
<title>PDFObject Example</title>
<script type="text/javascript" src="pdfobject.js"></script>
<script type='text/javascript'>

function embedPDF(){

  var myPDF = new PDFObject({ 

    url: 'sample.pdf',
    pdfOpenParams: { search: 'location' }

  }).embed();  

}

window.onload = embedPDF;

</script></head>
<body>
</body>
</html>

静态HTML方法:

<html>
<head>
<title>PDFObject Example</title>
</head>
<body>
<object data='sample.pdf#search=location' 
        type='application/pdf' 
        width='100%' 
        height='100%'>

  <p>It appears your Web browser is not configured to display PDF files. 
  No worries, just <a href='sample.pdf'>click here to download the PDF file.</a></p>

</object>
</body>
</html>

暂无
暂无

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

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