在嵌入式pe:documentViewer上使用javascript进行搜索

在嵌入式pe:documentViewer上使用javascript进行搜索,javascript,pdf,pdf.js,primefaces-extensions,Javascript,Pdf,Pdf.js,Primefaces Extensions,我有一个web应用程序,它使用primefaces extensions中的documentViewer来查看pdf文件 我需要使用javascript将查询传递到短语搜索,以便在找到我的查询的正确位置打开pdf文件。我将在打开documentViewer所用按钮的oncomplete属性中使用此javascript(pdfQuery): <p:commandButton action="#{searchController.openPDF}" oncomplete="PF('pdf_d

我有一个web应用程序,它使用primefaces extensions中的documentViewer来查看pdf文件

我需要使用javascript将查询传递到短语搜索,以便在找到我的查询的正确位置打开pdf文件。
我将在打开documentViewer所用按钮的oncomplete属性中使用此javascript(pdfQuery):

<p:commandButton action="#{searchController.openPDF}" 
oncomplete="PF('pdf_dlg').show();pdfQuery('Framework')" 
value="open PDF" update="pdf" />

<p:dialog header="#{searchController.pdfTitle}"
  widgetVar="pdf_dlg" 
responsive="true" dynamic="true" >
    <h:form id="pdf">
        <pe:documentViewer value="#{pdfBean.tempPdfFile}"/>
    </h:form>
</p:dialog>

不幸的是,无法识别来自
pdf.viewer.js
的方法
PDFViewerApplication
。我不知道如何访问它。

导航到此处的Showcase页面:

现在使用Chrome F12或您喜爱的浏览器打开控制台窗口。 在中键入以下代码:

window.frames[0].PDFViewerApplication.findBar.open();
注意到FindBar打开了吗?所以现在您可以编写一个脚本,通过访问PDFViewerApplication来实现您想要的功能

var pdfViewer=window.frames[0].PDFViewerApplication;
pdfViewer.findBar.open();
pdfViewer.findBar.findField.value=“我的文本”;
pdfViewer.findBar.highlightAll.checked=true;
pdfViewer.findBar.findNextButton.click();

因为documentViewer在IFRAME中加载了一个应用程序,所以在加载docviewer时,您可能需要执行一些特殊的操作来访问您试图在PDF查询中使用的PDFaApplication。看到这里的这个线程,我发现IFRAME正在加载。谢谢你提供的信息。我不确定第一部分定义了
pdfHideButton
功能。当我把它放在页面底部时,我得到一个错误:pdfHideButton没有定义。如果我把它放在标题中,我的页面根本不会被呈现。我做错了什么?pdfHideButton我只是在加载的JS文件中声明。你有一个JS文件,你在你的页面上包括在你的应用程序中的其他东西吗?好的,我在我的页面上有你的pdfHideButton工作示例代码。这是一个开始。下一步将尝试在加载时触发短语搜索。非常好。请发回如果你得到你的脚本工作!太好了,它起作用了!但还是有一个小问题。将代码放入IFRAME加载部分,pdfViewer仍然无法加载/识别。我在控制台中看到这是因为脚本在
pdf.viewer.js
之前启动。是否有办法在iframe加载完成后执行脚本?是的,您需要使用probbably document.ready()jquery函数而不是iframe onLoad,甚至可能需要使用setTimeOut来等待,直到加载为止。
function triggerSearch(tx_query) {
    $('iframe').on('load',
         function () {
            if (typeof PDFViewerApplication.findController !== 'undefined') {
               PDFViewerApplication.findController.executeCommand('find', {
                  query: tx_query,
                  caseSensitive: false,
                  highlightAll: true,
                  findPrevious: true
              });
         }
    });
}