thiagoelg / node-printer

Native node.js printer
125 stars 75 forks source link

Need help with auto ejecting #32

Closed PimTournaye closed 2 years ago

PimTournaye commented 2 years ago

Using a BIXOLON BK3-31

I can print stuff perfectly, only problem I have is that the tickets aren't being eject from my machine. I sadly can't figure out what to send along while using printDirect, here's my code snippet.

printRaw(text){
        nodeprinter.printDirect({
            data: Buffer.from(Itext), 
            printer:this.name,
            type: "RAW",
            success:function(){ console.log("printed: \n \n"+text);},
            error:function(err){console.log(err);}
        });
    }

I've dug through the manual but I don't know how to configure this Memory switch stuff. Cutting alright, it's just that auto eject stuff / presenter mode thing I'm nowhere near getting

Thanks for any help

PimTournaye commented 2 years ago

I found the stuff I needed after all and by scrolling through.a bunch of past issues, I managed to make my machine work. Here's what I'm doing in case anyone is wondering.

const INITIAL_PRINTER = '\x1B\x40';
const PAPER_EJECT = '\x1D\x65\x05';
const PAPER_CUTTING = '\x08\x56\x31';

printRaw(text) {
    let modifiedText = '\n \n' + text + "\n \n \n \n"

    nodeprinter.printDirect({
      data: Buffer.from(INITIAL_PRINTER) + Buffer.from(modifiedText)  + Buffer.from(PAPER_CUTTING) + Buffer.from(PAPER_EJECT),
      printer: this.name,
      type: "RAW",
      success: function () {
        console.log("printed: \n" + text + '\n \n');
      },
      error: function (err) {
        console.log(err);
      }
    });
  }

I'm adding extra whitespace since the spacing is a bit weird with my model.