Spaces:
Sleeping
Sleeping
Commit
·
045b303
1
Parent(s):
bca6bc0
implement stable version of zooming
Browse files
frontend/src/components/DocumentViewer.jsx
CHANGED
|
@@ -71,6 +71,18 @@ const DocumentViewer = ({ selectedFile, documentData, onPageChange, preloadedHig
|
|
| 71 |
scrollToChunk(0);
|
| 72 |
};
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
// Call onDocumentReady only once when utils become available
|
| 75 |
const callOnDocumentReady = () => {
|
| 76 |
if (onDocumentReady && !documentReadyCalledRef.current && highlighterUtilsRef.current) {
|
|
@@ -185,7 +197,30 @@ const DocumentViewer = ({ selectedFile, documentData, onPageChange, preloadedHig
|
|
| 185 |
}
|
| 186 |
return (
|
| 187 |
<div className="bg-white rounded-lg shadow-sm flex flex-col relative" style={{ width: '100%', height: '100%' }}>
|
| 188 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
<div style={{ height: '500px' }}>
|
| 191 |
<PdfLoader document={pdfUrl} workerSrc='/pdf.worker.min.js'>
|
|
@@ -193,6 +228,7 @@ const DocumentViewer = ({ selectedFile, documentData, onPageChange, preloadedHig
|
|
| 193 |
<PdfHighlighter
|
| 194 |
enableAreaSelection={(event) => event.altKey}
|
| 195 |
pdfDocument={pdfDocument}
|
|
|
|
| 196 |
utilsRef={(_pdfHighlighterUtils) => {
|
| 197 |
highlighterUtilsRef.current = _pdfHighlighterUtils;
|
| 198 |
callOnDocumentReady();
|
|
|
|
| 71 |
scrollToChunk(0);
|
| 72 |
};
|
| 73 |
|
| 74 |
+
const zoomIn = () => {
|
| 75 |
+
if (zoom < 4) {
|
| 76 |
+
setZoom(prev => prev + 0.1);
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
const zoomOut = () => {
|
| 81 |
+
if (zoom > 0.2) {
|
| 82 |
+
setZoom(prev => prev - 0.1);
|
| 83 |
+
}
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
// Call onDocumentReady only once when utils become available
|
| 87 |
const callOnDocumentReady = () => {
|
| 88 |
if (onDocumentReady && !documentReadyCalledRef.current && highlighterUtilsRef.current) {
|
|
|
|
| 197 |
}
|
| 198 |
return (
|
| 199 |
<div className="bg-white rounded-lg shadow-sm flex flex-col relative" style={{ width: '100%', height: '100%' }}>
|
| 200 |
+
<div className="flex justify-between items-center p-2 border-b">
|
| 201 |
+
<h2>{documentData?.filename || 'Document'}</h2>
|
| 202 |
+
<div className="flex items-center gap-2">
|
| 203 |
+
<button
|
| 204 |
+
title="Zoom out"
|
| 205 |
+
onClick={zoomOut}
|
| 206 |
+
className="px-2 py-1 border rounded hover:bg-gray-100"
|
| 207 |
+
disabled={zoom <= 0.2}
|
| 208 |
+
>
|
| 209 |
+
-
|
| 210 |
+
</button>
|
| 211 |
+
<span className="text-sm text-gray-600 min-w-12 text-center">
|
| 212 |
+
{(zoom * 100).toFixed(0)}%
|
| 213 |
+
</span>
|
| 214 |
+
<button
|
| 215 |
+
title="Zoom in"
|
| 216 |
+
onClick={zoomIn}
|
| 217 |
+
className="px-2 py-1 border rounded hover:bg-gray-100"
|
| 218 |
+
disabled={zoom >= 4}
|
| 219 |
+
>
|
| 220 |
+
+
|
| 221 |
+
</button>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
|
| 225 |
<div style={{ height: '500px' }}>
|
| 226 |
<PdfLoader document={pdfUrl} workerSrc='/pdf.worker.min.js'>
|
|
|
|
| 228 |
<PdfHighlighter
|
| 229 |
enableAreaSelection={(event) => event.altKey}
|
| 230 |
pdfDocument={pdfDocument}
|
| 231 |
+
pdfScaleValue={zoom}
|
| 232 |
utilsRef={(_pdfHighlighterUtils) => {
|
| 233 |
highlighterUtilsRef.current = _pdfHighlighterUtils;
|
| 234 |
callOnDocumentReady();
|