Skip to content

Commit 74a9283

Browse files
authored
Fix PDF download functionality: ensure correct file location and headers
1 parent 4f894b9 commit 74a9283

3 files changed

Lines changed: 37 additions & 27 deletions

File tree

.github/workflows/build-and-deploy-tutorial.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,32 @@ jobs:
173173
echo "✅ Pages setup completed successfully"
174174
echo "📄 Site will be deployed from ./build/site directory"
175175
176-
# Verify PDF generation and copy to UI bundle expected location
177-
- name: Verify PDF generation and copy to UI bundle expected location
176+
# Verify PDF generation and copy to correct location for download
177+
- name: Verify PDF generation and copy to correct location for download
178178
run: |
179179
if [ -f "./build/assembler/microprofile-tutorial/6.1/microprofile-tutorial.pdf" ]; then
180180
echo "✅ PDF generated in assembler location"
181181
PDF_SIZE=$(stat -f%z "./build/assembler/microprofile-tutorial/6.1/microprofile-tutorial.pdf" 2>/dev/null || stat -c%s "./build/assembler/microprofile-tutorial/6.1/microprofile-tutorial.pdf")
182182
echo "PDF Size: ${PDF_SIZE} bytes"
183183
184-
# Copy PDF to location expected by UI bundle download link
184+
# Copy PDF to the exact location the download link expects
185+
# The download link is ../../microprofile-tutorial/6.1/microprofile-tutorial.pdf
186+
# From /microprofile-tutorial/6.1/index.html, this resolves to /microprofile-tutorial/6.1/microprofile-tutorial.pdf
185187
mkdir -p "./build/site/microprofile-tutorial/6.1/"
186188
cp "./build/assembler/microprofile-tutorial/6.1/microprofile-tutorial.pdf" \
187189
"./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf"
188-
echo "✅ PDF copied to UI bundle expected location"
189-
ls -la ./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf
190+
echo "✅ PDF copied to download location: /microprofile-tutorial/6.1/microprofile-tutorial.pdf"
190191
191-
# Also copy assembler directory for backup access
192-
cp -r ./build/assembler ./build/site/
193-
echo "✅ Assembler directory copied for backup access"
192+
# Verify the copy was successful
193+
if [ -f "./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf" ]; then
194+
echo "✅ PDF verification successful"
195+
ls -la ./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf
196+
else
197+
echo "❌ PDF copy failed"
198+
exit 1
199+
fi
194200
195-
# Create .htaccess for GitHub Pages to force PDF downloads
201+
# Create .htaccess for GitHub Pages to ensure proper PDF serving
196202
cat > ./build/site/.htaccess << 'EOF'
197203
# Set proper MIME type for PDF files
198204
<Files "*.pdf">
@@ -203,17 +209,17 @@ jobs:
203209
Header set Pragma "no-cache"
204210
Header set Expires "0"
205211
</Files>
206-
207-
# Ensure PDF files are served correctly
208-
RewriteEngine On
209-
RewriteCond %{REQUEST_FILENAME} \.pdf$
210-
RewriteRule ^(.*)$ $1 [L,T=application/pdf]
211212
EOF
212213
213-
echo "✅ Download headers configured for PDFs"
214+
# Also create PDF-specific .htaccess in the PDF directory
215+
cp supplemental-ui/pdf-htaccess "./build/site/microprofile-tutorial/6.1/.htaccess"
216+
echo "✅ PDF-specific .htaccess created"
217+
218+
echo "✅ PDF download headers configured"
214219
else
215-
echo "⚠️ PDF not found in assembler location"
220+
echo " PDF not found in assembler location"
216221
find . -name "*.pdf" -type f
222+
exit 1
217223
fi
218224
219225
# Copy assembler directory to site for PDF access via UI bundle

supplemental-ui/partials/head-meta.hbs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@
66
pdfLinks.forEach(link => {
77
// Only modify links that contain 'microprofile-tutorial.pdf'
88
if (link.href.includes('microprofile-tutorial.pdf')) {
9-
// Ensure the link points to the correct absolute path
10-
const baseUrl = window.location.origin;
11-
const correctPath = baseUrl + '/microprofile-tutorial/6.1/microprofile-tutorial.pdf';
12-
link.href = correctPath;
13-
// Set a proper download filename
9+
// Don't modify the href - let it use the original relative path
10+
// Just ensure it has the download attribute with proper filename
1411
link.setAttribute('download', 'microprofile-tutorial.pdf');
15-
// Add click handler for additional debugging
16-
link.addEventListener('click', function(e) {
17-
console.log('PDF download clicked. URL:', this.href);
18-
// Let the default download behavior proceed
19-
});
2012
console.log('PDF download link configured:', link.href);
2113
}
2214
});
@@ -26,4 +18,4 @@
2618
{{!-- Favicons --}}
2719
<link rel="icon" href="{{{uiRootPath}}}/img/favicon.svg" type="image/svg+xml">
2820
<link rel="alternate icon" href="{{{uiRootPath}}}/img/favicon.png" type="image/png">
29-
<link rel="shortcut icon" href="{{{uiRootPath}}}/img/favicon.png" type="image/png";
21+
<link rel="shortcut icon" href="{{{uiRootPath}}}/img/favicon.png" type="image/png">

supplemental-ui/pdf-htaccess

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# PDF-specific .htaccess configuration
2+
AddType application/pdf .pdf
3+
Header set Content-Type "application/pdf"
4+
Header set Content-Disposition "attachment; filename=\"microprofile-tutorial.pdf\""
5+
Header set Cache-Control "no-cache, no-store, must-revalidate"
6+
Header set Pragma "no-cache"
7+
Header set Expires "0"
8+
9+
# Allow access to PDF files
10+
<Files "*.pdf">
11+
Require all granted
12+
</Files>

0 commit comments

Comments
 (0)