Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Last active July 21, 2021 05:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RichardBray/23decdec877c0e54e6ac2bfa4b0c512f to your computer and use it in GitHub Desktop.
Save RichardBray/23decdec877c0e54e6ac2bfa4b0c512f to your computer and use it in GitHub Desktop.
Downloading a base 64 pdf code
/**
* 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