diff --git a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/Highlighter.ts b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/Highlighter.ts index 94542af3..68bd93c5 100644 --- a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/Highlighter.ts +++ b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/Highlighter.ts @@ -97,7 +97,7 @@ export class Highlighter { * Update text content HTML elements * @param textContentDivs HTML elements where text content items are rendered */ - setTextContentDivs(textContentDivs?: HTMLCollection) { + setTextContentDivs(textContentDivs?: HTMLCollection | Element[]) { this.pdfTextContentLayout?.setDivs(textContentDivs); } diff --git a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/textLayout/PdfTextContentTextLayout.ts b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/textLayout/PdfTextContentTextLayout.ts index d33c27b9..553d1034 100644 --- a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/textLayout/PdfTextContentTextLayout.ts +++ b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/textLayout/PdfTextContentTextLayout.ts @@ -12,7 +12,7 @@ import { HtmlBboxInfo, PdfTextContentInfo, TextLayout } from './types'; export class PdfTextContentTextLayout implements TextLayout { private readonly textContentInfo: PdfTextContentInfo; readonly cells: PdfTextContentTextLayoutCell[]; - private divs: HTMLCollection | undefined; + private divs: HTMLCollection | Element[] | undefined; constructor(textContentInfo: PdfTextContentInfo, pageNum: number, htmlBboxInfo?: HtmlBboxInfo) { this.textContentInfo = textContentInfo; @@ -48,7 +48,7 @@ export class PdfTextContentTextLayout implements TextLayout = ({ async (signal: AbortSignal) => { if (textLayerWrapper && loadedText) { const { textContent, viewport, page } = loadedText; - let textDivs!: HTMLCollection; + let textDivs!: HTMLCollection | Element[]; const builder = new TextLayerBuilder({ pdfPage: loadedPage, @@ -86,6 +86,10 @@ const PdfViewerTextLayer: FC = ({ textContentItems ); adjustTextDivs(normalizedTextDivs, normalizedTextContentItems, scale); + + // update values that will be returned, to use normalized values + textDivs = normalizedTextDivs; + textContent.items = normalizedTextContentItems; } } });