- When you get base64 string from API encoded browser will not understand the format so need to convert base64 string into pdf using below method
const linkSource = 'data:application/pdf;base64,' + 'JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpbmVzIDIgMCBSDQovUGFnZXMgMyAwIFINCj4+DQplbmRvYmoNCg0KMiAwIG9iag0KPDwNCi9UeXBlIC9';
const downloadLink = document.createElement("a");
const fileName = "sample.pdf";
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
`
Credits: https://stackoverflow.com/a/51998228
Top comments (0)