0

I get a base64 file(pdf) from server,which I have to open in new tab and download it,and when download is over I have to close that tab,in angular.I used this but its not working

this.http.get(`url`)
        .subscribe((response: any) => {
            const filePath = 'data:application/pdf;base64,' + response.data;
            const aTag: any = document.createElement('a');
            const fileName = response.name;
            aTag.href = filePath;
            aTag.download = fileName;
            document.body.appendChild(aTag);
            window.open(filePath, '_blank');
            aTag.click();
            document.body.removeChild(aTag);
            window.close();
        }, (error) => {
            this.notificationMsgService.errorHandler(error);
        })
Reaper
  • 402
  • 3
  • 13

1 Answers1

0

Earlier I faced that issue ,it will be solved by appending a tag after opening a new tab

this.http.get(`url`)
    .subscribe((response: any) => {
        const filePath = 'data:application/pdf;base64,' + response.data;
        const aTag: any = document.createElement('a');
        const fileName = response.name;
        aTag.href = filePath;
        aTag.download = fileName;
        window.open(filePath, '_blank');
        document.body.appendChild(aTag);
        aTag.click();
        document.body.removeChild(aTag);
        window.close();
    }, (error) => {
        this.notificationMsgService.errorHandler(error);
    })
Reaper
  • 402
  • 3
  • 13