Skip to content

Commit e59bd9d

Browse files
committed
pdf preview error fixing
1 parent cf45bd0 commit e59bd9d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/pages/Documentation.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import Footer from '@/components/ui/Footer';
1515

1616
const Documentation = () => {
1717
const [pdfPreview, setPdfPreview] = useState<{ title: string, url: string } | null>(null);
18+
const [pdfError, setPdfError] = useState(false);
1819

1920
// Get base path for assets
2021
const basePath = import.meta.env.BASE_URL;
2122

2223
const handleViewPDF = (title: string, url: string) => {
2324
setPdfPreview({ title, url });
25+
setPdfError(false);
2426
};
2527

2628
// Hardware images - will loop continuously (duplicate for seamless loop)
@@ -280,12 +282,27 @@ const Documentation = () => {
280282
</div>
281283

282284
{/* PDF Embed */}
283-
<div className="pt-16 h-full">
284-
<iframe
285-
src={pdfPreview.url}
286-
className="w-full h-full"
287-
title={pdfPreview.title}
288-
/>
285+
<div className="pt-16 h-full bg-muted/10 relative">
286+
{pdfError ? (
287+
<div className="flex flex-col items-center justify-center h-full gap-4">
288+
<FileText className="w-16 h-16 text-muted-foreground" />
289+
<p className="text-muted-foreground">Unable to preview PDF in browser</p>
290+
<a href={pdfPreview.url} download>
291+
<Button>
292+
<Download className="mr-2 w-4 h-4" />
293+
Download PDF Instead
294+
</Button>
295+
</a>
296+
</div>
297+
) : (
298+
<iframe
299+
src={`${pdfPreview.url}#toolbar=0&navpanes=0&scrollbar=1`}
300+
className="w-full h-full border-0"
301+
title={pdfPreview.title}
302+
allow="fullscreen"
303+
onError={() => setPdfError(true)}
304+
/>
305+
)}
289306
</div>
290307

291308
{/* Download Button */}

0 commit comments

Comments
 (0)