I am trying to generate simple PDF file using below code but failing with error : "Failed to load PDF document":
var downloadLink = document.createElement('a');
downloadLink.target = '_blank';
downloadLink.download = 'name_to_give_saved_file.pdf';
// convert downloaded data to a Blob
var blob = new Blob(['downloadedFile'], { type: 'application/pdf' });
// create an object URL from the Blob
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
// set object URL as the anchor's href
downloadLink.href = downloadUrl;
// append the anchor to document body
document.body.append(downloadLink);
// fire a click event on the anchor
downloadLink.click();
Tried to follow many existing answers(e.g. How to build PDF file from binary string returned from a web-service using javascript) but did not get any solution yet. Please help. Thanks in advance :)