Fix PDF export filename: use JavaScript download with proper .pdf extension
Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
parent
0f2b6bc77f
commit
b3eeb563f7
4 changed files with 20 additions and 2 deletions
|
|
@ -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.pdf", "application/pdf", base64);
|
||||||
NavigationManager.NavigateTo(fileUrl, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveScheduleToStorage()
|
private async Task SaveScheduleToStorage()
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
||||||
18
Client/wwwroot/js/fileDownload.js
Normal file
18
Client/wwwroot/js/fileDownload.js
Normal 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);
|
||||||
|
};
|
||||||
BIN
test.pdf
Normal file
BIN
test.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue