1 possible answer(s) on “Download option

  1. For who is still looking for a solution:

    Typescript:

    private pdf: PDFDocumentProxy;
    
    onLoaded(pdf: PDFDocumentProxy) {
        this.pdf = pdf;
    }
    
    download() {
        this.pdf.getData().then((u8) => {
            let blob = new Blob([u8.buffer], {
                type: 'application/pdf'
            });
            if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                // IE11 and Edge
                window.navigator.msSaveOrOpenBlob(blob, 'Certificate.pdf');
            } else {
                // Chrome, Safari, Firefox, Opera
                let url = URL.createObjectURL(blob);
                this.openLink(url);
                // Remove the link when done
                setTimeout(function () {
                    window.URL.revokeObjectURL(url);
                }, 5000);
            }
        });
    }
    
    private openLink(url: string) {
        let a = document.createElement('a');
        // Firefox requires the link to be in the body
        document.body.appendChild(a);
        a.style.display = 'none';
        a.href = url;
        a.download = 'Certificate.pdf';
        a.click();
        // Remove the link when done
        document.body.removeChild(a);
    }