Last active
July 21, 2021 05:26
-
-
Save RichardBray/23decdec877c0e54e6ac2bfa4b0c512f to your computer and use it in GitHub Desktop.
Downloading a base 64 pdf code
This file contains hidden or 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
/** | |
* Creates an anchor element `<a></a>` with | |
* the base64 pdf source and a filename with the | |
* HTML5 `download` attribute then clicks on it. | |
* @param {string} pdf | |
* @return {void} | |
*/ | |
function downloadPDF(pdf) { | |
const linkSource = `data:application/pdf;base64,${pdf}`; | |
const downloadLink = document.createElement("a"); | |
const fileName = "vct_illustration.pdf"; | |
downloadLink.href = linkSource; | |
downloadLink.download = fileName; | |
downloadLink.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment