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

How to use the search feature in PDFObject?

我正在使用 PDFObject to try to search a PDF for a certain term and highlight it. The website actually generates code for such an application automatically 但出于某种原因,这段代码实际上根本没有搜索我的 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 对象中查找(并突出显示)的搜索词是一个名为 'location' 的词。

我把这段代码复制到我的整体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 提供的代码完美运行,谢谢。我只剩一个问题了;我使用 'this' 代码(见下文)为搜索词添加高亮显示,但是当我搜索一个词时,高亮本身不会自动显示;知道如何解决吗?所以基本上,当 PDF 在 Acrobat 中打开时,搜索功能运行良好,并且在左侧菜单窗格中,我可以看到搜索结果;然而,我自己搜索的术语并没有在加载 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>

HERE 是 index.html 时 PDF 当前的样子(搜索功能正常工作,但默认情况下不突出显示我的术语)。

HERE 是我希望 PDF 在加载时的样子 index.html;如果您实际单击搜索词,则会出现一个突出显示框(如图所示)。对于我试图在地图上查找的任何搜索词,我希望该突出显示框与 PDF 一起加载。

如有任何帮助,我们将不胜感激,Pipwerks 你真的是救星,感谢你的帮助!

可惜了PDF Open Parameters are Adobe-specific and don't work in most PDF readers, including the built-in PDF viewers in Chrome and Firefox. In fact, it's been an issue/feature request in Google's Chromium project快五年了

它在 Adob​​e 中是否适合您 Reader?

-- 更新--

重新阅读您的 post,您的代码不正确。您混淆了 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>