Skip to content

Instantly share code, notes, and snippets.

@abcdeepakr
Created January 24, 2022 07:18
Show Gist options
  • Save abcdeepakr/046e22a2ff8f9e52f3949cd4a773170c to your computer and use it in GitHub Desktop.
Save abcdeepakr/046e22a2ff8f9e52f3949cd4a773170c to your computer and use it in GitHub Desktop.
Open print dialogue.
const displayPrintDialogue = (generatedBlob) => { // generate blob
var blob = new Blob([generatedBlob], { type: "application/pdf" });
var blobURL = URL.createObjectURL(blob);
let iframe = document.createElement("iframe"); //load content in an iframe to print later
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.src = blobURL;
iframe.onload = function () {
setTimeout(function () {
iframe.focus();
iframe.contentWindow.print();
}, 1);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment