mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-05-31 07:11:00 +02:00
Avoid setting page-content for a previous document in the PDFFindController.prototype.#extractText method
Given that all of the relevant API methods are asynchronous it's possible, although quite unlikely, that the existing "is the document active" check won't catch all situations where the document was closed in the middle of searching.
This commit is contained in:
parent
a6e2a42df1
commit
aa08b02a5b
@ -909,6 +909,11 @@ class PDFFindController {
|
||||
try {
|
||||
const pdfPage = await pdfDoc.getPage(i + 1);
|
||||
const textContent = await pdfPage.getTextContent(textOptions);
|
||||
|
||||
if (pdfDoc !== this._pdfDocument) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
const strBuf = [];
|
||||
|
||||
for (const textItem of textContent.items) {
|
||||
@ -921,6 +926,10 @@ class PDFFindController {
|
||||
[this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] =
|
||||
normalize(strBuf.join(""));
|
||||
} catch (ex) {
|
||||
if (pdfDoc !== this._pdfDocument) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
console.error(`Unable to get text content for page ${i + 1}`, ex);
|
||||
// Page error -- assuming no text content.
|
||||
[this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user