Created
March 10, 2025 14:51
-
-
Save danila-schelkov/01ff0bd235462c643c17b277acd57aea to your computer and use it in GitHub Desktop.
A small script for downloading pdfs from sites with PDF Embedder
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
function saveToFile(byteArray, fileName) { | |
const blob = new Blob([byteArray], { type: "application/pdf" }); | |
const url = URL.createObjectURL(blob); | |
// Note: A link element is used to set the file name | |
const a = document.createElement("a"); | |
a.href = url; | |
a.download = fileName; | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
URL.revokeObjectURL(url); | |
} | |
// TODO: handle multiple pdf viewers | |
const pdfUrl = jQuery(document.querySelector(".pdfemb-viewer")).data("pdf-url"); | |
PDFEMB_NS.pdfembGetPDF(pdfUrl, function (t, e) { | |
console.log("Gotcha!"); | |
// Note: A search query is used to name the pdf file, which may not work properly on some sites | |
saveToFile(t, window.location.search.substring(1) + ".pdf") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment