From bb01284ba883913b36d908d29d1c520b8ee56e24 Mon Sep 17 00:00:00 2001 From: ggq-admin Date: Sun, 19 Oct 2025 19:52:16 +0200 Subject: [PATCH] Add image display functionality to document viewer This commit implements comprehensive image extraction display for PDF documents: 1. Created useDocumentImages.js composable: - fetchPageImages() function to retrieve images for specific page - getImageUrl() helper to generate full image URLs - Proper loading states and error handling 2. Created ImageOverlay.vue component: - Positioned absolutely over PDF canvas at correct coordinates - Semi-transparent border to indicate image location - Hover tooltip displaying extracted OCR text with confidence level - Click handler to open full-size image modal - Accessibility support (keyboard navigation, ARIA labels) - Responsive positioning with smooth hover effects 3. Modified DocumentView.vue: - Imported and integrated useDocumentImages composable - Added ImageOverlay components for each extracted image - Integrated FigureZoom modal for full-size image viewing - Automatically fetches images when page changes - Displays image count in header - Tracks canvas dimensions for proper image positioning Features: - Images overlay at exact PDF coordinates using scale conversion - OCR text displayed in tooltip on hover - Full-size image view on click with zoom/pan controls - Reduced motion and high contrast mode support - Seamless integration with existing PDF viewer Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude --- client/src/components/ImageOverlay.vue | 291 ++++++++++++++++++++ client/src/composables/useDocumentImages.js | 81 ++++++ client/src/views/DocumentView.vue | 75 ++++- 3 files changed, 440 insertions(+), 7 deletions(-) create mode 100644 client/src/components/ImageOverlay.vue create mode 100644 client/src/composables/useDocumentImages.js diff --git a/client/src/components/ImageOverlay.vue b/client/src/components/ImageOverlay.vue new file mode 100644 index 0000000..a51ae8c --- /dev/null +++ b/client/src/components/ImageOverlay.vue @@ -0,0 +1,291 @@ + + + + + diff --git a/client/src/composables/useDocumentImages.js b/client/src/composables/useDocumentImages.js new file mode 100644 index 0000000..045b988 --- /dev/null +++ b/client/src/composables/useDocumentImages.js @@ -0,0 +1,81 @@ +/** + * Document Images Composable + * Handles fetching and managing extracted images from PDF documents + */ + +import { ref } from 'vue' + +export function useDocumentImages() { + const images = ref([]) + const loading = ref(false) + const error = ref(null) + + /** + * Fetch images for a specific page of a document + * @param {string} documentId - The document UUID + * @param {number} pageNumber - The page number (1-indexed) + * @returns {Promise} Array of image objects + */ + async function fetchPageImages(documentId, pageNumber) { + if (!documentId || !pageNumber) { + console.warn('Missing documentId or pageNumber') + images.value = [] + return [] + } + + loading.value = true + error.value = null + + try { + const response = await fetch(`/api/documents/${documentId}/images?page=${pageNumber}`) + + if (!response.ok) { + if (response.status === 404) { + // No images found for this page - not an error + images.value = [] + return [] + } + throw new Error(`Failed to fetch images: ${response.statusText}`) + } + + const data = await response.json() + images.value = data.images || [] + + return images.value + } catch (err) { + console.error('Error fetching page images:', err) + error.value = err.message + images.value = [] + return [] + } finally { + loading.value = false + } + } + + /** + * Get the full image URL for a specific image + * @param {string} documentId - The document UUID + * @param {string} imageId - The image ID + * @returns {string} Full URL to the image + */ + function getImageUrl(documentId, imageId) { + return `/api/documents/${documentId}/images/${imageId}` + } + + /** + * Clear current images + */ + function clearImages() { + images.value = [] + error.value = null + } + + return { + images, + loading, + error, + fetchPageImages, + getImageUrl, + clearImages + } +} diff --git a/client/src/views/DocumentView.vue b/client/src/views/DocumentView.vue index 6bf3777..9ea9448 100644 --- a/client/src/views/DocumentView.vue +++ b/client/src/views/DocumentView.vue @@ -18,6 +18,9 @@
Page {{ currentPage }} / {{ totalPages }} + + ({{ pageImages.length }} {{ pageImages.length === 1 ? 'image' : 'images' }}) +
@@ -77,21 +80,46 @@

{{ error }}

-
- +
+
+ + + + +
+ + +