lsongdev / node-escpos

🖨️ ESC/POS Printer driver for Node.js
https://npmjs.org/escpos
Other
1.38k stars 423 forks source link

Encode picture #245

Open Nehved opened 4 years ago

Nehved commented 4 years ago

Hi there. I have some troubles with printing images. Here my source code `const device = new escpos.Network(IP); const options = { encoding: 'CP860' }; const printer = new escpos.Printer(device, options); const tux = path.join(__dirname, 'tux.png');

escpos.Image.load(tux, (image) => { device.open(() => { printer.text('hello here'); printer.image(image); printer.cut(); printer.close(); }); });`

below I attached photo of result, thanks for your help)

photo_2019-12-17_18-02-05

Nehved commented 4 years ago

Btw, I use Ubuntu 18.04 + Electron app, printer HP.

Psychopoulet commented 4 years ago

printer.image is an async method https://github.com/song940/node-escpos/blob/master/printer.js

Nehved commented 4 years ago

@Psychopoulet thanks for response, I refactored my code in next way:

const { Printer, Network, Image } = require('escpos');
const device = new Network(ip);
const printer = new Printer(device);
const tux = path.join(__dirname, 'tux.png');

Image.load(tux, (image) => {
  device.open(async () => {
    await printer.image(image);
    printer.cut().close();
  });
});

result still the same, could you pls provide working example?

Psychopoulet commented 4 years ago

... in your electron app do you use this package in a front way ??

Nehved commented 4 years ago

@Psychopoulet no, it is located in my main file for backend part, like "electron.js"

Psychopoulet commented 4 years ago

what is your printer's model ? are you sure thate escpos standard is enable on it ?