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

标签 javascript pdf pdf.js primefaces-extensions

我有一个网络应用程序,它使用 primefaces 扩展中的 documentViewer 来查看 pdf 文件。

我需要使用 javascript 将查询传递给 phraseSearch,以便在找到查询的正确位置打开 pdf 文件。
我将在以下位置使用此 javascript (pdfQuery)我用来打开 documentViewer 的按钮的 oncomplete 属性:

<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.js 相关的 SO 上发现了类似的问题,但与 primefaces 扩展无关:
PDF.js - Using search function on embedded PDF
Search using code on Embedded PDFJS

有什么想法可以实现这一点吗?
如何访问嵌入的 primefaces pdf.js?
提前非常感谢。

编辑:
现在我被困在这里了。这段 JavaScript 不起作用:

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
              });
         }
    });
}

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

最佳答案

导航至此处的展示页面: https://www.primefaces.org/showcase-ext/sections/documentviewer/advanced.jsf

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

window.frames[0].PDFViewerApplication.findBar.open();

注意到 FindBar 打开了吗?因此,现在您可以通过访问 PDFViewerApplication 来编写一个完全符合您要求的脚本。

var pdfViewer = window.frames[0].PDFViewerApplication;
pdfViewer.findBar.open();
pdfViewer.findBar.findField.value = "My text";
pdfViewer.findBar.highlightAll.checked= true;
pdfViewer.findBar.findNextButton.click();

关于javascript - 在嵌入式 pe 上使用 javascript 进行搜索 :documentViewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58781170/

相关文章:

c++ - 波普勒替代品

css - 为什么 scaleX 会导致绝对定位的元素向左移动?

Javascript提示-数据隐藏在ie中

javascript - Slick JS 垂直,两个元素在同一行

python - 在 Python 中搜索和替换 pdf 中的文本

javascript - PDF内容逻辑操作

javascript - 在完整日历中更新现有事件时如何防止事件重叠?

javascript 不移动元素

javascript - Pdf.js 的加载栏

连字符语言中的 Primefaces 扩展 DocumentViewer 不起作用