ShiftScheduler/Client/wwwroot/js/fileDownload.js
copilot-swe-agent[bot] b3eeb563f7 Fix PDF export filename: use JavaScript download with proper .pdf extension
Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
2025-08-20 06:12:48 +00:00

18 lines
No EOL
660 B
JavaScript

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);
};