General
Downloadpdf

Download PDF

This Download PDF Function is used for Downloading files responsed back from Backend.

Function

downlaodPDF.ts
function downloadPDF = (path, filename) =>{
    const anchor = document.createElement('a');
    anchor.href = path;
    anchor.download = filename;
    document.body.appendChild(anchor);
    anchor.click();
    document.body.removeChild(anchor);
}

Usage

export.tsx
const Report = () => {
    function(){
        SettingService.doGetDownLoadWavier(id).then((res) => {
            const url = window.URL.createObjectURL(new Blob([res.data], { type: 'application/pdf' }));
            const fileName = name + '.pdf';
            downloadPdf(url, fileName);
            URL.revokeObjectURL(url);
        });
    }
}