Skip to content

Instantly share code, notes, and snippets.

@danila-schelkov
Created March 10, 2025 14:51
Show Gist options
  • Save danila-schelkov/01ff0bd235462c643c17b277acd57aea to your computer and use it in GitHub Desktop.
Save danila-schelkov/01ff0bd235462c643c17b277acd57aea to your computer and use it in GitHub Desktop.
A small script for downloading pdfs from sites with PDF Embedder
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