UNPKG

react-pdf-annotations

Version:
23 lines (22 loc) 1.22 kB
const getClientRectsNew1 = (range, pages, pdfViewer) => { const clientRects = Array.from(range.getClientRects()); const [startPage, endPage] = pages; const filteredRects = clientRects.filter(el => el.height > 0 && el.height < 100); const result = []; const startPageView = pdfViewer.viewer.getPageView(startPage.number - 1); const endPageView = pdfViewer.viewer.getPageView(endPage.number - 1); const startPageRect = startPageView.canvas.getClientRects()[0]; const endPageRect = endPageView.canvas.getClientRects()[0]; const fRect = filteredRects[0]; const lRect = filteredRects[filteredRects.length - 1]; result.push({ points: startPageView.viewport.convertToPdfPoint(fRect.left - startPageRect.x, fRect.top - startPageRect.y).concat(startPageView.viewport.convertToPdfPoint(fRect.right - startPageRect.x, fRect.bottom - startPageRect.y)), page: startPage.number }); result.push({ points: endPageView.viewport.convertToPdfPoint(lRect.left - endPageRect.x, lRect.top - endPageRect.y).concat(endPageView.viewport.convertToPdfPoint(lRect.right - endPageRect.x, lRect.bottom - endPageRect.y)), page: endPage.number }); return result; }; export default getClientRectsNew1;