"use client" import { Document, Page, pdfjs } from "react-pdf" import { useState } from "react" import "react-pdf/dist/Page/AnnotationLayer.css" import "react-pdf/dist/Page/TextLayer.css" // Configure PDF.js worker to use local package pdfjs.GlobalWorkerOptions.workerSrc = new URL( "pdfjs-dist/build/pdf.worker.min.mjs", import.meta.url, ).toString() interface PdfViewerProps { url: string | null | undefined } export function PdfViewer({ url }: PdfViewerProps) { const [numPages, setNumPages] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) if (!url) { return (
No PDF URL provided
) } function onDocumentLoadSuccess({ numPages }: { numPages: number }) { setNumPages(numPages) setLoading(false) setError(null) } function onDocumentLoadError(error: Error) { setError(error.message || "Failed to load PDF") setLoading(false) } return (
{loading && (
Loading PDF...
)} {error && (
Error: {error}
)}
{numPages && (
{Array.from(new Array(numPages), (_, index) => ( ))}
)}
) }