In my application I need people to be able to download the PDF file that I'm displaying, is there a way to do that?
@kevinariasf
Do you use an URL or Uint8Array for the source?
@thwefl I use an Uint8Array, btw I need them to be able to print it too
I did with simply call this function on click
printpdf() {
this.winRef.open(this.pdfSrc).print();
}
Are you thinking of adding a download option? I use a URL for the source. right now I navigate them away from this viewer and just href them to a new tab using the URL. this gives them all the viewing, downloading and printing we want.... but it defeats the purpose of having the viewer which we want.
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);
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
For who is still looking for a solution:
Typescript: