Created
January 8, 2021 12:29
-
-
Save AugustoCalaca/f9d8edb21acf12f22254c5e1374365f0 to your computer and use it in GitHub Desktop.
how to convert a base64 to pdf url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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