Skip to content

Instantly share code, notes, and snippets.

@maggocnx
Last active August 29, 2015 14:07
Show Gist options
  • Save maggocnx/a02eff4d69cdacd12421 to your computer and use it in GitHub Desktop.
Save maggocnx/a02eff4d69cdacd12421 to your computer and use it in GitHub Desktop.
Print
isNodeWebkit = (typeof process !== "undefined") ;
$("body").append('<canvas id="printCanvas" width="384" height="'+ canvasHeight + '"></canvas>');
var canvas = document.getElementById('printCanvas');
this.drawCanvas(canvas,order, function(){
if(isNodeWebkit){
fs = require("fs");
var exec = require("child_process").exec;
var __dirname = process.cwd();
var imgData = canvas.toDataURL().replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(imgData, 'base64');
var imgPath =__dirname + "/tmp.png";
fs.writeFile(imgPath , buf, function(err){
// exec("convert tmp.png -flatten -negate -monochrome -colors 2 print.bmp", function(){
exec("convert tmp.png -flip -flatten -negate -monochrome -colors 2 bmp:- | tail -c+35 > /dev/thprint", function(){
$ionicLoading.hide();
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment