I receive base64 pdf string from the server. I need to show the correct pdf file name instead of the blob name.
It must be in the new tab
const b64 = data.fileData;
const link = document.createElement("a");
link.innerHTML = "Download PDF file";
link.download = data.fileName;
link.href = "data:application/octet-stream;base64," + b64;
const byteString = atob(link.href.split(",")[1]);
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
const blob = new Blob([ab], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
window.open(url);
this is what it's showing in my url:
localhost:8080/d03908a1-6bbc-49e8-929d-e0c4cd313095
I need to change the name to my custom name like myPdf.pdf
what have a tried and also not working:
// const newWindow = window.open('', data.fileName, "width=800,height=1200");
// if (newWindow) {
// setTimeout( () => {
// const dataUrl = window.URL.createObjectURL(blob);
// const title = newWindow.document.createElement('title');
// const iframe = newWindow.document.createElement('iframe');
// title.appendChild(document.createTextNode(data.fileName));
// newWindow.document.head.appendChild(title);
// iframe.setAttribute('src', dataUrl);
// iframe.setAttribute('width', "100%");
// iframe.setAttribute('height', "100%");
// newWindow.document.body.appendChild(iframe);
// setTimeout( () => {
// // For Firefox it is necessary to delay revoking the ObjectURL
// window.URL.revokeObjectURL(dataUrl);
// }, 100);
// }, 100);
// }
is some has there code ? https://base64.guru/converter/decode/pdf
this is working but i can't download and to nothing: https://base64.guru/developers/javascript/examples/decode-pdf