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 @@ + + + + + + + + + Extracted Text + + {{ Math.round(image.textConfidence * 100) }}% confidence + + + {{ image.extractedText }} + + + + + + + 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 }} - - + + + + + + + + + +
{{ error }}