diff --git a/web/viewer.js b/web/viewer.js index be512736f..8d7c51f24 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1231,6 +1231,8 @@ var PageView = function pageView(container, pdfPage, id, scale, this.renderingState = RenderingStates.INITIAL; this.resume = null; + this.textContent = null; + var anchor = document.createElement('a'); anchor.name = '' + this.id; @@ -1485,6 +1487,22 @@ var PageView = function pageView(container, pdfPage, id, scale, var self = this; function pageViewDrawCallback(error) { + var visiblePages = PDFView.getVisiblePages(); + var pageView = PDFView.getHighestPriority(visiblePages, PDFView.pages, + PDFView.pageViewScroll.down); + + if (pageView === self) { + if (!self.textContent) { + self.textContent = {}; + self.pdfPage.getTextContent().then( + function textContentResolved(textContent) { + self.textContent = textContent; + textLayer.setTextContent(textContent); + } + ); + } + } + self.renderingState = RenderingStates.FINISHED; if (self.loadingIconDiv) { @@ -1890,10 +1908,16 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { textDiv.style.fontFamily = fontName; textDiv.style.left = text.geom.x + 'px'; textDiv.style.top = (text.geom.y - fontHeight) + 'px'; - textDiv.textContent = PDFJS.bidi(text, -1); - textDiv.dir = text.direction; + + // The `text.direction` is added inside the PDFJS.bidi function. + // textDiv.textContent = PDFJS.bidi(text, -1); + // textDiv.dir = text.direction; this.textDivs.push(textDiv); }; + + this.setTextContent = function textLayerBuilderSetTextContent(textContent) { + // When calling this function, we assume rendering the textDivs has finished + }; }; document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {