Raj Shekhar Dev

Back

Save blob as PDF

Following snippet allowed me to save a blob. Here we are creating an a tag, making it invisible, putting the blob as url and then clicking it to download the file.

const saveBlob = (blob, fileName) => {
	var a = document.createElement("a");
	document.body.appendChild(a);
	a.style = "display: none";
	var url = URL.createObjectURL(new Blob([blob], { type: "application/pdf" }));
	a.href = url;
	a.download = fileName;
	a.click();
	window.URL.revokeObjectURL(url);
};