PDF.js Express Version 7.3.0
Detailed description of issue
I followed the advanced search example of the documentation to annotate texts. However i did not trigger the TextSearchInit from documentLoad but later after a server response. The server response is an array with search terms.
Based on the server response TextSearchInit is then executed multiple times (the onDocumentEnd event handler triggers the search for the next search term).
The onResult event handler is only triggered for the results of the first search term. For each other search term onResult is not triggered.
When i skip the first search term, the second search term is found and its results are highlighted without problems.
Do i have to reset the search somehow or is it not possible to execute multiple searches after another with TextSearchInit?
Expected behaviour
I expect that all searches return results.
Does your issue happen with every document, or just one?
With multiple documents.
Code snippet
drawNextAnnotation() {
if(this.annotationsQueue && this.annotationsQueue.length) {
const nextAnnotation = this.annotationsQueue[0];
this.drawAnnotation(nextAnnotation.phrase, nextAnnotation.state);
this.annotationsQueue.splice(0, 1);
}
}
drawAnnotation(phrase, state) {
var { docViewer, CoreControls, annotManager, Annotations } = this.wvInstance;
const colorMap = {
'ok': new Annotations.Color(83, 142, 21, 0.3),
'danger': new Annotations.Color(194, 10, 10, 0.2),
'warning': new Annotations.Color(161, 152, 2, 0.3),
'inactive': new Annotations.Color(166, 166, 166, 0.3)
}
const searchMode = CoreControls.Search.Mode.HIGHLIGHT;
const searchOptions = {
fullSearch: true,
onResult: (result) => {
if (result.resultCode === CoreControls.Search.ResultCode.FOUND) {
console.log(result);
if (!result.quads.length) return;
const color = colorMap[state];
const textQuad = result.quads[0].getPoints();
const annot = new Annotations.TextHighlightAnnotation();
annot.X = textQuad.x1;
annot.Width = textQuad.x2 - textQuad.x1;
annot.PageNumber = result.pageNum;
annot.Y = textQuad.y3;
annot.Height = textQuad.y1 - textQuad.y3;
annot.FillColor = color;
annot.StrokeColor = color;
annot.Quads = [textQuad];
annotManager.addAnnotation(annot);
annotManager.redrawAnnotation(annot);
}
},
onDocumentEnd: (result) => {
this.drawNextAnnotation();
}
}
docViewer.textSearchInit(phrase, searchMode, searchOptions);
}