I am new to using Java's print service and from reading articles I see that you need the the right DocFlavor to print properly.
Question: What DocFlavor to use for printing the receipt in a POS thermal printer?
I've had success with
DocFlavor.BYTE_ARRAY.AUTOSENSE printing to Zebra and Datamax printers. This is when the printer is being driven by commands sent directly (as byte arrays) by the program with the built-in printer language (EPL, DPL, ZPL): select this font, print this string here, etc.
In addition to
AUTOSENSE there are some other options for image and text formats. I would guess these depend on the drivers to support them correctly. You send the bytes for an image or text, and the driver does the work of converting that to something the printer understands. So you lose a bit (or a lot) of control, but let the driver to the work. That's the usual trade-off.