Skip to content

Commit

Permalink
fix: return normalized text divs/content values (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpedemonte authored Aug 13, 2024
1 parent 000e66b commit a357da2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { HtmlBboxInfo, PdfTextContentInfo, TextLayout } from './types';
export class PdfTextContentTextLayout implements TextLayout<PdfTextContentTextLayoutCell> {
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;
Expand Down Expand Up @@ -48,7 +48,7 @@ export class PdfTextContentTextLayout implements TextLayout<PdfTextContentTextLa
/**
* set PDF text content item divs
*/
setDivs(divs: HTMLCollection | undefined) {
setDivs(divs: HTMLCollection | Element[] | undefined) {
this.divs = divs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PdfRenderedText = {
/**
* Text span DOM elements rendered on the text layer
*/
textDivs: HTMLCollection;
textDivs: HTMLCollection | Element[];

/**
* Pdf page viewport used to render text items
Expand Down Expand Up @@ -69,7 +69,7 @@ const PdfViewerTextLayer: FC<PdfViewerTextLayerProps> = ({
async (signal: AbortSignal) => {
if (textLayerWrapper && loadedText) {
const { textContent, viewport, page } = loadedText;
let textDivs!: HTMLCollection;
let textDivs!: HTMLCollection | Element[];

const builder = new TextLayerBuilder({
pdfPage: loadedPage,
Expand All @@ -86,6 +86,10 @@ const PdfViewerTextLayer: FC<PdfViewerTextLayerProps> = ({
textContentItems
);
adjustTextDivs(normalizedTextDivs, normalizedTextContentItems, scale);

// update values that will be returned, to use normalized values
textDivs = normalizedTextDivs;
textContent.items = normalizedTextContentItems;
}
}
});
Expand Down

0 comments on commit a357da2

Please sign in to comment.