Giter VIP home page Giter VIP logo

Comments (16)

pushpak avatar pushpak commented on June 1, 2024 6

Here's how to send ESC/POS commands and few links which is MUST read

example: prints text and feeds 10 lines and cuts the paper. (tested on Epson TM-T88V thermal printer and working)

String.prototype.toBytes = function() {
        var arr = []
        for (var i=0; i < this.length; i++) {
            arr.push(this[i].charCodeAt(0))
        }
        return arr;
    }

    var printData = "hello world ESC/POS".toBytes().concat([0x01B, 0x64, 10, 0x1d, 0x56, 0x00]);

    printer.printDirect({
        data: new Buffer(printData)
        , printer:'TM_T88V_S_A_192_168_1_152'
        , type: 'RAW'
        , success:function(jobID){
            console.log("sent to printer with ID: "+jobID);
        }
        , error:function(err){console.log(err);}
    });

Note: 0x1d, 0x56, 0x00 is the esc/pos cut command

from node-printer.

Sangd8 avatar Sangd8 commented on June 1, 2024 1

Sorry, i tried eveything above, none of it working....
I'm using POS 58 Thermal Printer. I can printer is working, but when i try to send an print command from nodejs use nore-printer. If i set type is TEXT The Printer just print a blank line, any else type, printer says nothing. This is my entire code

var printer = require("printer");

String.prototype.toBytes = function (){
var arr = [];
for (var i = 0; i < this.length; i++) {
arr.push(this[i].charCodeAt(0))
}
return arr;
};

var printData = "hello world ESC/POS".toBytes().concat([0x01B, 0x64, 3]);

printer.printDirect({
data: new Buffer(printData)
, printer: 'POS58 10.0.0.6'
, type: 'RAW'
, success: function (jobID){
console.log("sent to printer with ID: " + jobID);
}
, error: function (err){
console.log(err);
}
});

from node-printer.

tojocky avatar tojocky commented on June 1, 2024

I think you could use RAW type to send direct to printer. examples/print_raw.js. Let me know if this works. Otherwise you have to find the appropiate type format name.

from node-printer.

jcerdan avatar jcerdan commented on June 1, 2024

OK, I have tried but no way... will search hoe the hell this should work.
best,

from node-printer.

jcerdan avatar jcerdan commented on June 1, 2024

Yes! Thanks pushpak. I've looking for this for some time now!
link1 is really useful.
no need to print images now. but I keep that link in mind!

from node-printer.

tojocky avatar tojocky commented on June 1, 2024

Thanks @pushpak for your input. Closing this issue.

from node-printer.

tariqbuilds avatar tariqbuilds commented on June 1, 2024

Hey @jcerdan, link 1 from @pushpak 's comment doesn't seem to be working anymore. Can anyone provide me with an updated link?

I'm trying to print to a thermal printer with Node.js and suffering some roadblocks.

from node-printer.

jcerdan avatar jcerdan commented on June 1, 2024

Hi @afaqurk.
It works fine for me. If you can't see it install npm module node-escpos as it's a file describing commands for printer to cut, align, etc...
This is the module https://github.com/StadiumRunner/node-escpos
The file is located in lib/commands.js
best,

from node-printer.

tariqbuilds avatar tariqbuilds commented on June 1, 2024

Sorry, I meant the second link. Specifically, this one.

from node-printer.

pushpak avatar pushpak commented on June 1, 2024

@afaqurk check my updated comment with alternate mirror link

from node-printer.

tariqbuilds avatar tariqbuilds commented on June 1, 2024

Thank you!

from node-printer.

tojocky avatar tojocky commented on June 1, 2024

Be care full, Nodejs chars are în UTF8 format. You have to transform imto ASCII I suppose.

from node-printer.

Sangd8 avatar Sangd8 commented on June 1, 2024

How suppose can i do that? I'm new on nodejs. I'm trying to build a app with NWJS. Thanks

from node-printer.

Sangd8 avatar Sangd8 commented on June 1, 2024

I tried this
new Buffer(printData, 'ascii')
Still nothing.

from node-printer.

Sangd8 avatar Sangd8 commented on June 1, 2024

Hey, i found out. I used
new Uint8Array(printData).buffer
It's working now. Thanks :)

from node-printer.

nohaelsheweikh avatar nohaelsheweikh commented on June 1, 2024

Hey , Sangd8 , can you please show me full code for this if it's working for you ?
i have same problem now , and i used Uint8Array(printData).buffer but it shows error to me
Argument 0 must be a string or Buffer

from node-printer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.