Hubertformin / electron-pos-printer

Electron-pos-printer is a plugin that works to ease paper formatting and printing to thermal printers. it currently supports 80mm, 78mm, 76mm, 58mm, 57mm and 44mm printers thermal printers. it is built with Electron.js and Node.js
Apache License 2.0
316 stars 101 forks source link

[Fix] - Silent Print not wokring. #113

Open zain-335 opened 10 months ago

zain-335 commented 10 months ago

I'm using @3ksy/electron-pos-printer lib inside my electron react project to print receipts from main-process(nodejs). Printer is working only when slient: false. when i set the silent: true inside PrintOptions, it prints empty receipts. here is my code.

import { PosPrinter, PosPrintData, PosPrintOptions } from '@3ksy/electron-pos-printer'

const options: PosPrintOptions = {
  preview: false,
  margin: '0 0 0 0',
  boolean: '',
  copies: 1,
  timeOutPerLine: 400,
  pageSize: '80mm', // page size,
  silent: true
}

export const handlePrintReceipt = async (_, data: PosPrintData[]) => {
  PosPrinter.print(data, options)
    .then(console.log)
    .catch((error) => {
      console.log('hello error')
      console.error(error)
    })
}

Current Response

Printer not printing any content when silent: true but printing all the content as expected when silent: false.

Expected Result

Printer should print content when setting silent : true in PrintOptions

alfianlensundev commented 9 months ago

i have the same problem

ranulrandombage commented 9 months ago

Having the same issue prints nothing but the paper cuts.

aldoanizio commented 8 months ago

I have the same problem here

aldoanizio commented 8 months ago

Hi @zain-335 @alfianlensundev @ranulrandombage I found the reason for this "bug". It's not related to the library but the electron itself.

Looks like the electron versions after 24x does not print the content when the silent mode is enabled.

Please take a look at these issues:

https://github.com/electron/electron/issues/17523 https://github.com/electron/electron/issues/31705

I've tested the library with electron 15x version and everything worked.

I'll proceed testing with all versions (from 15 to latest) and discover since when this bug is present.

ranulrandombage commented 5 months ago

Hi @aldoanizio,

Were you able to find a fix for this issue, I urgently need to find a solution for this, if not I might have to move to a different library :(

I tried upgrading electron v25.3.1 where they've mentioned that silent printing was fixed but the issue persists.

aldoanizio commented 5 months ago

Hi @ranulrandombage I had to downgrade Electron to 15x version and everything worked!

To be more specific I'm using Electron v15.5.7. As you are using a newer version of Electron if you choose to downgrade be aware you have to change the function to catch the printers list.

In electron newer versions when you invoke the printers list function you receive a promise. In 15x version the function will return the printers list as an array of objects.