Is it possible to force a thermal printer to print a specific character? (Dollar sign is printing as Yen)

1k Views Asked by At

I bought a cheap thermal receipt printer for some practice (Amazon B07848ZBXT). It seems to try to adhere to the ESC/POS standard.

As best I can tell it has 2 fonts controlled by bytes {27, 77, 0} and {27, 77, 1}, the latter being a smaller font. However when I'm using the smaller font, $ prints as ¥ (see demo print). Their own Amazon image has this also. Would there be a way to say stop replacing character codes or is this a 'low level' replacement that probably can't be overridden?

For my code I'm using Java. I store everything in String and get a byte array at the end and print it via javax.print. A sample is below.

Picture of receipt where $ is shown in bigger font but ¥ appears in the smaller font

final byte[] Init = {27, 64};
String stringToPrint= new String(Init);

byte[] feedStart = {27,101,(byte)2};  //(Side note, is there someway to combine the byte[] initialization and the String() usage?)
stringToPrint += new String(feedStart);
stringToPrint += "My text";

byte[] feed = {27,101,(byte)1};
stringToPrint += new String(feed );

byte[] feedAndCut = {29, 'V', 66, 0};
stringToPrint += new String(feedAndCut );

byte[] byteArray = stringToPrint.getBytes();

AttributeSet attrSet = new HashPrintServiceAttributeSet(new PrinterName(PRINTER_NAME, null));
DocPrintJob job = PrintServiceLookup.lookupPrintServices(null, attrSet)[0].createPrintJob();

DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(byteArray, flavor, null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);

job.print(doc, null);
1

There are 1 best solutions below

1
queeg On

It's been a long time, but...

You can run the printer in graphics mode where you control each and every dot. And you can run it in text mode where you send characters and the printer needs to know how to print them. I guess you are using text mode currently.

Very likely you just need to configure the charset/codepage for your printer to match your Java program's output. From what you state the printer may be set to some Japanese charset. Grab the vendor's manual to see how it is configured.