diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 0d8eb5a2a..75163f685 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -906,40 +906,27 @@ class PDFFindController { resolve(); return; } - await pdfDoc - .getPage(i + 1) - .then(pdfPage => pdfPage.getTextContent(textOptions)) - .then( - textContent => { - const strBuf = []; + try { + const pdfPage = await pdfDoc.getPage(i + 1); + const textContent = await pdfPage.getTextContent(textOptions); + const strBuf = []; - for (const textItem of textContent.items) { - strBuf.push(textItem.str); - if (textItem.hasEOL) { - strBuf.push("\n"); - } - } - - // Store the normalized page content (text items) as one string. - [ - this._pageContents[i], - this._pageDiffs[i], - this._hasDiacritics[i], - ] = normalize(strBuf.join("")); - resolve(); - }, - reason => { - console.error( - `Unable to get text content for page ${i + 1}`, - reason - ); - // Page error -- assuming no text content. - this._pageContents[i] = ""; - this._pageDiffs[i] = null; - this._hasDiacritics[i] = false; - resolve(); + for (const textItem of textContent.items) { + strBuf.push(textItem.str); + if (textItem.hasEOL) { + strBuf.push("\n"); } - ); + } + // Store the normalized page content (text items) as one string. + [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = + normalize(strBuf.join("")); + } catch (ex) { + 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]] = + ["", null, false]; + } + resolve(); }); } }