Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created July 8, 2015 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmactough/5d6f8bb7ec9383facb20 to your computer and use it in GitHub Desktop.
Save danmactough/5d6f8bb7ec9383facb20 to your computer and use it in GitHub Desktop.
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