Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Not using this really clever bit
function () {
actions.zoomForPrint();
window.requestAnimationFrame(function () {
const imgData = getImageFromCanvas();
// atob to base64_decode the data-URI
const imgSrc = atob(imgData.split(",")[1]);
// Use typed arrays to convert the binary data to a Blob
const buffer = new ArrayBuffer(imgSrc.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < imgSrc.length; i++) {
view[i] = imgSrc.charCodeAt(i) & 0xff;
}
var blob = new Blob([buffer], { type: "application/octet-stream" });
// Use the URL object to create a temporary URL
var url = window.URL.createObjectURL(blob);
// Download
location.href = url;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment