Skip to content

Commit 3261373

Browse files
committed
Add PDF open link and mobile fallback in PDFViewer: Introduced a button to open the PDF in a new tab and added a fallback message for mobile users indicating potential preview issues. Enhanced styles for better responsiveness and Safari compatibility.
1 parent 62fbbf4 commit 3261373

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

src/components/PDFViewer.astro

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const {
1919
<span class="pdf-label">PDF</span>
2020
<span class="pdf-title">{title}</span>
2121
</div>
22+
<a href={src} class="pdf-btn" target="_blank" rel="noopener noreferrer">
23+
Open PDF
24+
</a>
2225
</div>
2326

2427
<div class="pdf-frame">
@@ -27,8 +30,17 @@ const {
2730
src={`${src}#toolbar=1&statusbar=0&navpanes=0&view=FitH`}
2831
title={title}
2932
loading="lazy"
33+
type="application/pdf"
34+
allow="fullscreen"
3035
></iframe>
3136
</div>
37+
38+
<div class="pdf-mobile-fallback">
39+
<p>
40+
PDF preview may not be supported on this device. Use the button above to
41+
open the document in your browser or PDF viewer.
42+
</p>
43+
</div>
3244
</div>
3345

3446
<style>
@@ -118,23 +130,61 @@ const {
118130
height: 100%;
119131
border: none;
120132
background: #0d131b;
133+
/* Safari-specific fixes */
134+
-webkit-overflow-scrolling: touch;
135+
}
136+
137+
/* Safari desktop: ensure PDF renders properly */
138+
@supports (-webkit-appearance: none) {
139+
.pdf-iframe {
140+
display: block;
141+
}
142+
}
143+
144+
.pdf-mobile-fallback {
145+
display: none;
146+
padding: 0.75rem 1rem 1rem;
147+
font-size: 0.85rem;
148+
color: var(--text-secondary);
121149
}
122150

123151
@media (max-width: 768px) {
124152
.pdf-viewer-wrapper {
125153
margin: 1.5rem 0;
126154
width: 100%;
127155
align-self: stretch;
156+
height: auto !important;
128157
}
129158
.pdf-header {
130159
flex-wrap: wrap;
131160
gap: 0.5rem 0.75rem;
161+
justify-content: space-between;
162+
}
163+
.pdf-btn {
164+
flex: 1;
165+
min-width: 120px;
166+
text-align: center;
132167
}
133168
.pdf-frame {
134-
min-height: 420px;
169+
display: none;
135170
}
136171
.pdf-iframe {
137172
min-height: 420px;
138173
}
174+
.pdf-mobile-fallback {
175+
display: block;
176+
}
177+
}
178+
179+
/* Safari iOS specific: hide iframe, show fallback */
180+
@supports (-webkit-touch-callout: none) {
181+
@media (max-width: 768px) {
182+
.pdf-frame {
183+
display: none !important;
184+
}
185+
.pdf-mobile-fallback {
186+
display: block !important;
187+
}
188+
}
139189
}
140190
</style>

0 commit comments

Comments
 (0)