lsongdev / lsongdev/node-escpos

When image loaded with express route , it prints first time but second time it prints garbage

Open
#177 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.6k
Forks
443
PR merge metrics
No merged PRs in 30d

Description

// Select the adapter based on your printer type
// return res.json({success:false , body:req.body});
const device = new escpos.Network(req.body.printer.ip, req.body.printer.port);
// const usbDevice = new escpos.USB();
// const usbPrinter = new escpos.Printer(usbDevice);
// const usbDevice = new escpos.USB();

// Adapter
// Constructors
// You can choose your adapter type as USB, Serial, Network, or Console.

// USB(vid, pid)
// const usbDevice = new escpos.USB(0x01, 0xff);
// vid(Vendor Id) and pid(Product Id) can be checked with the lsusb command or escpos.USB.findPrinter() method.

// const device = new escpos.Network('localhost');
// const device = new escpos.Serial('/dev/usb/lp0');

// return res.json({success:false , body:req.body , ip:req.body.ip , port:req.body.port ,device:device});

var options = { encoding: "Shift_JIS" /* default */ }
// encoding is optional
var tux = __dirname + '/images/ors.png';
var tab=" ";
var space;
if(req.body.language =='JP'){
space = tab.repeat(2);
}
else{
space = "";
}

var printer = new escpos.Printer(device, options);
new escpos.Image.load(tux, function (image) {
device.open(function () {
printer
.font('b')
.align('ct')
.style('bu')
.size(1, 1)
.raster(image, 'dwdh').
align("lt")

.text("\n")

.text("店舗名")
.text("TEL : 052-884-7250 ")
.text("いらっしゃいません")
.text(new Date())
.text("")
.text("<< 領収書 >>")
.text("")
.text("--------------------------------------------")
// .align('rt')
.text (req.value)
// .align('lt')
.text("--------------------------------------------")

.text("預り金 \t\t\t\t " +space+ " ¥" + req.body.sales.given.toLocaleString())
.text("お釣り \t\t\t\t " +space+ " ¥" + req.body.sales.return_back.toLocaleString())
.text("")
.cut('full')
.cashdraw(5)
.beep(1, 100)
.close();
res.json({success:true ,msg:"succesfully done the print" });

// .text('私はラジェスです。名古屋で住んでいます')
// .text("동해물과 백두산이 마르고 \n 닳도록.Rajesh" , "EUC-KR")
// .barcode('1234567', 'EAN8')

// .qrimage('https://facebook.com', function(err){

// this.cashdraw(2);
// this.beep(1, 100); // how much beep , and time of beep
// this.cut('full');

// this.close();

// });
});
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Express route code using escpos.Network, escpos.Image.load, device.open, and printer.close. Reproduce two consecutive requests with the same image and inspect whether the device or printer state is reused incorrectly. Done means repeated image prints produce the expected output instead of garbage.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, nodejs
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.