pdf.js - 如何知道 pdfFindController.executeCommand 何时执行

标签 pdf.js

我正在使用 Angular 7 构建一个 web 应用程序,我尝试实现搜索功能,如 https://mozilla.github.io/pdf.js/web/viewer.html .

我有它的工作,但我喜欢在官方查看器中显示当前匹配和总匹配。我的代码如下所示:

this.pdfFindController.executeCommand('find', this.searchCommand);
let { current, total, } = this.pdfFindController._requestMatchesCount();
this.currentMatch = current;
this.numberOfSearchMatches = total;
console.log('Number of matches', this.currentMatch, '/', 
this.numberOfSearchMatches);

当我运行此代码时,this.currentMatch 显示的是前一场比赛而不是当前比赛。如果我像这样修改代码:
this.pdfFindController.executeCommand('find', this.searchCommand);
setTimeout(() => {    
let { current, total, } = 
    this.pdfFindController._requestMatchesCount();
    this.currentMatch = current;
    this.numberOfSearchMatches = total;
    console.log('Number of matches', this.currentMatch, '/', 
    this.numberOfSearchMatches);
}, 1000);

那么 this.currentMatch 包含正确的匹配号。所以我想我需要在调用 executeCommand 和 _requestMatcheCount 之间等待一些东西。我已经广泛搜索了代码,但我还没有找到一种方法来知道 executeCommand 何时完成,因此可以安全地调用 _requestMatchesCount。谁能告诉我我怎么知道 executeCommand 已经完成?

最佳答案

我们来了,可能有点晚了!
this.pdfComponent.pdfViewer.eventBus.on('updatefindmatchescount', data => { this.searchMatchesLength = data.matchesCount.total; });

关于pdf.js - 如何知道 pdfFindController.executeCommand 何时执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55128023/

相关文章:

ajax - Grails和pdf.js并通过ajax调用呈现pdf

javascript - 如何使用 pdf.js 获取 pdf 标题?

promise - pdf.js promise 的问题

pdf - :documentViewer not displaying digital signatures in PDF

javascript - 通过组合 pdf.js 和 pdf.worker.js 创建 pdf.js 的离线版本

pdf.js 不适用于 IE 9 和 10

javascript - IE 9 中的 pdf.js。警告 : Unhandled rejection: Error: Access is denied

javascript - PDF.js 查看器捏合缩放

python - 将 ViewerJS 与 Django 结合使用

firefox - 为什么用 pdf.js 打开 pdf 有时会导致 "save as.."对话框?