1

Sorry for the long winded question, I've spent a few days trying to figure this out and have so far found dozens of ways not to solve my problem.

I'm currently trying to use a Datamax O'Neill E Class Mark 3 printer to print some labels. The java application that generates the label data cannot be easily modified, and simply outputs plain text via a built in "print" function (output example below)

Unit name [LF]
Unit description [LF]
Quantity

When I print to a Ricoh printer it works (using CR+LF replacement in the Ricoh driver). However when I print to the label printer it does not. I've been advised that the label printer requires "control codes" and "encoded data" to be able to print.

I've been able to log the .prn files from the printer and when sending the exact same data from Notepad to he printer, the .prn file is much larger and appears to be "encoded" containing control codes.

This is entirely inside a windows environment using a networked printer (tried USB as well). I basically need something for my Java application to print to, that will add the necessary "encoding" to the data and then pass it along to the Datamax printer. Any ideas?

I'll try and post some samples tomorrow when I'm in the office as I'm currently typing this on mobile.

Jai Chauhan
  • 4,035
  • 3
  • 36
  • 62
CJPCNZ
  • 23
  • 6
  • I'm not clear on the details here. Does the Java application generate a .prn (text) file to disk or does it actually send it to the printer? If it was using the Java print API things would just work. If it generates a text file you'll need to print that (you could monitor a directory if it's always generated in the same place) as described by Carey. If using Java it has its own [print API](https://docs.oracle.com/javase/tutorial/2d/printing/). – Nick Westgate Aug 11 '16 at 22:21
  • The Java application uses its own (very odd) print function to output a raw data stream to the printer using port 9100. The printer is able to log .prn files for me to C:\ which in turn I can open with notepad and send via the print driver to the printer, resulting in a correctly encoded .prn file that the printer can now understand. – CJPCNZ Aug 12 '16 at 02:22
  • Thanks for clarifying. Yeah, 9100 is the "raw" or direct printing data port. Most printers will accept text here and just print it out, and possibly detect other language data if sent. Anyway, your solution works, and has saved you days of pain. ; - ) – Nick Westgate Aug 12 '16 at 02:34
  • Yeah I had expected it to print from raw data port, but according the the manufacturer, the printer doesn't understand plain text. – CJPCNZ Aug 12 '16 at 02:37

2 Answers2

1

What I ended up doing was using the printers logging feature to log all jobs to C:\printlogs\ and have a batch file that loops every few seconds to run notepad /P on each file in the folder and then clean them all up.

I know it's a messy workaround, but it works.

CJPCNZ
  • 23
  • 6
0

When you print text from something like Notepad, that text gets sent to a print driver that converts it into the format the printer understands. You can't generally add control codes to the text in Notepad and have it work because it won't be seen as anything other than plain text to be printed.

The programmer's manual for that printer can be found here. That gives you everything you need to know to print labels on that printer. But in order to send those commands to the printer, you can't just paste them into Notepad. You have to write them directly to the printer, bypassing the print driver. For that you're going to need to use the WritePrinter function. The sequence of steps for printing goes like this:

To begin a print job, call StartDocPrinter.
To begin each page, call StartPagePrinter.
To write data to a page, call WritePrinter.
To end each page, call EndPagePrinter.
Repeat 2, 3, and 4 for as many pages as necessary.
To end the print job, call EndDocPrinter.

The MSDN entry for WritePrinter includes a link to example code (in C).

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
  • Thanks for that, I am really hoping not to have to edit the application (it's closed source and has poor extension script support) but at least if it comes to that I have somewhere to start! – CJPCNZ Aug 10 '16 at 19:41