Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Last active January 8, 2019 22:32
Show Gist options
  • Save M-Yankov/ca6eee76970da048a2c7cb143606b397 to your computer and use it in GitHub Desktop.
Save M-Yankov/ca6eee76970da048a2c7cb143606b397 to your computer and use it in GitHub Desktop.
Download Html AS image png html2canvas
/* Test on Firefox 64.0
* See https://html2canvas.hertzen.com/
* https://github.com/niklasvh/html2canvas/
*
* Usage:
* Open a page
* Open developer console (F12)
* Paste the script below
* Click save image.
*
* Known issues:
* error messages appear on the console
* loading CSS, JS and fonts again before prompt for save (maybe caused by <a/> element clicking - need to investigate)
*/
var s1 = document.createElement('script');
s1.src = 'https://github.com/niklasvh/html2canvas/releases/download/v1.0.0-alpha.12/html2canvas.js';
document.body.appendChild(s1);
// Define the container to save as image
var targetContainer = $("#ilContentContainer").get(0);
// Special case for a page
$("#ilContentContainer input[disabled]").each((i,el) => {el.disabled = false; console.log('log')})
var imageName = $(".ilc_PageTitle").text() + ".png";
s1.onload = function () {
html2canvas(targetContainer).then((canvas) => {
var url = canvas.toDataURL();
$("<a>", {
href: url,
download: imageName
})
.on("click", function() {$(this).remove()})
.appendTo("body")[0].click()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment