anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
283 stars 74 forks source link

Zeros and one characters at the start and end of lines #89

Closed lukibeni closed 6 months ago

lukibeni commented 7 months ago

I have a problem with a Diebold Nixdorf P1200 printer. 0s and 1s appear randomly at the start and end of lines (see attached screenshot). I couldn't imagine what could cause this kind of problem, the same code works on all other printers. Could you help me with this issue? Here is the documentation of the printer if it helps: P1200-prog-manual.pdf

Steps to Reproduce

private fun printOnDiebold() { val printService = PrinterOutputStream.getPrintServiceByName("P1200") val printerOutputStream = PrinterOutputStream(printService) try { EscPos(printerOutputStream).use { escPos -> escPos.info() escPos.setCharacterCodeTable( EscPos.CharacterCodeTable.values() .find { it.charsetName == "cp437" } ) escPos.feed(4) escPos.write("Árvíztűrő tükörfúrógép Árvíztűrő tükörfúrógép Árvíztűrő tükörfúrógép") escPos.feed(4) escPos.cut(EscPos.CutMode.FULL) } } catch (e: Exception) { throw e } }

Evidences

PXL_20240415_144937235 PXL_20240415_145759280

Chase22 commented 6 months ago

This might be a similar problem to #86, as in the printer does not support something being send to it.

What i did to verify was to directly send text to the printer and see if it gets printed correctly: escpos.outputStream.write(YourString.toByteArray(Charset.forName(pos.defaultCharsetName)))

If this is the case it's probably something in the Style Class not being supported by your printer

lukibeni commented 6 months ago

Thanks for your response, I already fixed it and the problem was with the Style indeed. I noticed that printing with PrintModeStyle works, so I tried to compare the normal Style and the PrintModeStyle byte by byte. I figured out if I skip the second byte everything works perfectly (except some other extensions functions, because the characters by line was not the same as for otherr printers.

byte[] modifiedBytes = new byte[configBytes.length - 1];
System.arraycopy(configBytes, 0, modifiedBytes, 0, 1); // Copy first byte
System.arraycopy(configBytes, 2, modifiedBytes, 1, configBytes.length - 2); // Copy rest of bytes skipping the second
configBytes = modifiedBytes;