Reputation: 1
When I click the download icon on the right corner, nothing happen. How to make it downloadable?
The following code i have used for PDF preview.
let pdfWindow = window.open("", "_blank")
pdfWindow.document.write("<iframe src='data:application/pdf;base64, " + yourDocumentBase64VarHere+"' width='100%' height='100%' allowfullscreen></iframe>")
Upvotes: 0
Views: 566
Reputation: 304
This works for me in all browsers!
viewPdf(base64String) {
let byteCharacters = atob(base64String);
let byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
let byteArray = new Uint8Array(byteNumbers);
let blob = new Blob([byteArray], { type: 'application/pdf' });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, 'Report.pdf');
}
else {
var fileURL = URL.createObjectURL(blob);
window.open(fileURL);
}
}
Upvotes: 1