Skip to content

Instantly share code, notes, and snippets.

@AugustoCalaca
Created January 8, 2021 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AugustoCalaca/f9d8edb21acf12f22254c5e1374365f0 to your computer and use it in GitHub Desktop.
Save AugustoCalaca/f9d8edb21acf12f22254c5e1374365f0 to your computer and use it in GitHub Desktop.
how to convert a base64 to pdf url
const base64ToPDF = (base64) => {
const byteString = window.atob(base64);
const arrayBuffer = new ArrayBuffer(byteString.length);
const int8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i += 1) {
int8Array[i] = byteString.charCodeAt(i);
}
const blob = new Blob([int8Array], { type: 'application/pdf' });
const pdfURL = URL.createObjectURL(blob);
return pdfURL;
};
export default base64ToPDF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment