Files
omni-tools/src/pages/tools/pdf/utils.ts
Ibrahima G. Coulibaly 5545f0f344 feat: protect pdf
2025-04-03 18:42:24 +00:00

17 lines
506 B
TypeScript

export function loadPDFData(url: string, filename: string): Promise<File> {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
window.URL.revokeObjectURL(url);
const blob = new Blob([xhr.response], { type: 'application/pdf' });
const newFile = new File([blob], filename, {
type: 'application/pdf'
});
resolve(newFile);
};
xhr.send();
});
}