Skip to content

Instantly share code, notes, and snippets.

@nazrdogan nazrdogan/print.js
Created Oct 19, 2018

Embed
What would you like to do?
saveCanvasImage() {
var dataUrl = this.canvasElement.toDataURL();
var imageData = this.canvasElement.toDataURL('image/jpeg').replace(/^data:image\/(png|jpg|jpeg);base64,/, ""); //remove mimetype
window["DatecsPrinter"].printImage(
imageData, //base64
canvas.width,
canvas.height,
1,
function() {
console.log("Printed");
},
function(error) {
alert(JSON.stringify(error));
}
)
};
let ctx = this.canvasElement.getContext('2d');
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // Clears the canvas
let name = new Date().getTime() + '.png';
let path = this.file.dataDirectory;
let options: IWriteOptions = { replace: true };
var data = dataUrl.split(',')[1];
let blob = this.b64toBlob(data, 'image/png');
this.file.writeFile(path, name, blob, options).then(res => {
this.storeImage(name);
}, err => {
console.log('error: ', err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.