Fix PDF export filename: Add .pdf extension to downloaded files (#13)

* Initial plan

* Fix PDF export filename: use JavaScript download with proper .pdf extension

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* Remove test PDF file from repository

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* Add year and month

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
This commit is contained in:
Copilot 2025-08-21 16:41:14 +02:00 committed by GitHub
parent 2dc437ac9c
commit b41d8d6b36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -104,8 +104,7 @@ namespace ShiftScheduler.Client.Pages
var response = await HttpClient.PostAsJsonAsync("api/shift/export_pdf", shiftsWithTransportList); var response = await HttpClient.PostAsJsonAsync("api/shift/export_pdf", shiftsWithTransportList);
var bytes = await response.Content.ReadAsByteArrayAsync(); var bytes = await response.Content.ReadAsByteArrayAsync();
var base64 = Convert.ToBase64String(bytes); var base64 = Convert.ToBase64String(bytes);
var fileUrl = $"data:application/octet-stream;base64,{base64}"; await JSRuntime.InvokeVoidAsync("downloadFile", $"Schedule {EditYear}-{EditMonth:00}.pdf", "application/pdf", base64);
NavigationManager.NavigateTo(fileUrl, true);
} }
private async Task SaveScheduleToStorage() private async Task SaveScheduleToStorage()

View file

@ -26,6 +26,7 @@
<a href="" class="reload">Reload</a> <a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<script src="js/fileDownload.js"></script>
<script src="_framework/blazor.webassembly.js"></script> <script src="_framework/blazor.webassembly.js"></script>
</body> </body>

View file

@ -0,0 +1,18 @@
window.downloadFile = (filename, contentType, base64Data) => {
const byteCharacters = atob(base64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: contentType });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
};