0

My Java application for Windows prints on thermal printers via spooler without any interaction with a print dialog (using the code snippet below).

I don't know why, but it ignores the device configuration settings in the Printer Properties dialog box (on Windows 7, right-click on a printer in Printers and Devices). Settings for emitting buzzer beeps or cutting the paper at the end of the document are ignored.

There are proprietary ESC/POS codes which can be used to achieve the same effect but some of them work for 'direct protocol' printing only. I'm trying not to use them and configure the Printer Properties instead, in order to simplify troubleshooting printing issues (although I'd adopt direct protocol as last resort in this case).

How to make the print job accept the Printer Properties config settings? Or if necessary how to use direct protocol?

File file = File.createTempFile("order", "tmp");
try (PrintWriter printWriter = new PrintWriter(file)) {
    printWriter.print(textToPrint);
}
DocPrintJob dpj = printService.createPrintJob();
InputStream stream = new ByteArrayInputStream(textToPrint.getBytes(StandardCharsets.UTF_8));
HashDocAttributeSet attributes = new HashDocAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(stream, flavor, attributes);
dpj.print(doc, new HashPrintRequestAttributeSet(new JobName("The Application", null)));
file.delete();
Piovezan
  • 3,215
  • 1
  • 28
  • 45
  • There is a set of manuals in the Advanced Printer Driver installer, so please refer to it or ask EPSON support if you still don't know? [Windows Printer Driver](https://download.epson-biz.com/modules/pos/index.php?page=soft&scat=31) – kunif Oct 01 '19 at 07:57
  • I don't know if this is an answer, but I've figured that I can use either `PrinterJob` and print as an image (actually a `Printable`/`Pageable`) while having the Windows configurations accepted, or use `DocPrintJob` and print strings but having the configurations ignored. I can't have both worlds (print strings and having the configurations to work). – Piovezan Oct 01 '19 at 20:04
  • So I can either draw strings into an image or PDF, or talk to the printer via direct protocol (which apparently means communicating via (virtual) serial port to the printer's USB connection. – Piovezan Oct 01 '19 at 20:13

0 Answers0