I am building a webapp with Angular 7 and I try to implement search functionality like in https://mozilla.github.io/pdf.js/web/viewer.html.
I have it working, but I like to show current match and total matches like in the official viewer. My code looks like this:
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);
When I run this code this.currentMatch is showing the previous match instead of the current match. If I modify the code like this:
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);
then this.currentMatch contains the correct match number. So I guess I need to wait for something between calling executeCommand and _requestMatcheCount. I have searched the code extensively, but I have not found a way to know when executeCommand has finished so _requestMatchesCount can be safely called. Can anybody tell me how I can know that executeCommand has finished?
Here we are, maybe a little late!
this.pdfComponent.pdfViewer.eventBus.on('updatefindmatchescount', data => {
this.searchMatchesLength = data.matchesCount.total;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With