简体   繁体   中英

How to send Raw Commands to Receipt Printer in Node.JS?

What I am Trying to do

Currently have a receipt printer that supports ESC/P raw printing.

I am building an app that will need to print receipts remotely.

How I am doing this

Sending data through PrintNodes API from my app to the printer.

I have used an NPM library 'ESCPOS' and have successfully printed a few samples.

(The 'ESCPOS' npm is not a remote printing library - but i did the test to make sure everything was working properly and it is)

My Issue

Print node requires that the content-type of your print job to be "raw_base64".

So I take my raw commands

Convert them to hex byte

0x1B"@"0x1B0x38'should be bold'

and then convert that to base_64

MHgxQiJAIjB4MUIweDM4J3Nob3VsZCBiZSBib2xkJw==

What I get printed is the plain text of decoded base64 rather than the rendered commands that I sent the printer.

The example receipt above should be the string "Should be bold" in bold.

What i get returned is all the hex values of my raw esc/p commands.

我的打印输出

What I've Done

I have tried ESCPOS (NPM library) and send data directly to the printer without Printnode and it prints perfect.

This leads me to believe that perhaps I am not sending the data correctly.

This is what I send in my post request to printnode api

let bodytosend = {
    printer: 69079558,  
    title: 'Sample Print Job',
    contentType: 'raw_base64',
    content: "MHgxQiJAIjB4MUIweDM4J3Nob3VsZCBiZSBib2xkJw==",
    source: 'Created from node app.js'
}

Just came across this repo.

receiptline Printable digital receipts
Transform markdown-like text to receipt printer commands or SVG images.
https://github.com/receiptline/receiptline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM