Skip to content

Commit

Permalink
fix: import TextLayer to get textDivs
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-eigenfeld committed Jun 4, 2024
1 parent 0435a15 commit adf7a01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { FC, useEffect, useRef, useCallback } from 'react';
import cx from 'classnames';
import { TextContent, TextItem, PDFPageProxy } from 'pdfjs-dist/types/src/display/api';
import { PageViewport } from 'pdfjs-dist/types/src/display/display_utils';
import { EventBus, TextLayerBuilder } from 'pdfjs-dist/web/pdf_viewer.mjs';
import { TextLayerBuilder } from 'pdfjs-dist/web/pdf_viewer.mjs';
import { TextLayer } from 'pdfjs-dist/build/pdf.mjs';
import useAsyncFunctionCall from 'utils/useAsyncFunctionCall';
import { PdfDisplayProps } from './types';

Expand Down Expand Up @@ -74,14 +75,20 @@ const PdfViewerTextLayer: FC<PdfViewerTextLayerProps> = ({
pdfPage: loadedPage
});
// trying to find a way to return textDivs
const textItems = textContent.items;
console.log('textItems', textItems);
// const textItems = textContent.items;
// const textDivs = processItemsToDivs(textItems);

textLayerWrapper.append(builder.div);
signal.addEventListener('abort', () => builder.cancel());

await _renderTextLayer(builder, textContent, textLayerWrapper, scale, viewport);
return { textContent, viewport, page, textDivs: [] };
const textLayer = new TextLayer({
textContentSource: textContent,
container: textLayerWrapper,
viewport
});
await textLayer.render();
return { textContent, viewport, page, textDivs: textLayer.textDivs };
}
return undefined;
},
Expand Down Expand Up @@ -142,6 +149,13 @@ async function _renderTextLayer(
// _adjustTextDivs(builder.textDivs, textContent.items as TextItem[], scale);
}

function processItemsToDivs(textItems: TextItem[] | null): HTMLElement[] | null {
console.log('items to process', textItems);
let textDivs = [];

return textDivs;
}

/**
* Adjust text span width based on scale
* @param textDivs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// declare module 'pdfjs-dist/build/pdf.worker.min.mjs';

declare module 'pdfjs-dist/build/pdf.mjs' {
export class TextLayer {
constructor({ textContentSource: TextContent, container: any, viewport: PageViewport });
render(): Promise;
textDivs: HTMLElement[];
}
}

// //
// // Declare modules and their types that is referred from PDF text layer rendering.
// // Unused properties are commented out
Expand Down

0 comments on commit adf7a01

Please sign in to comment.