giorgiline
giorgiline

Reputation: 1371

How to give format and print data to a ticket printer in Java

I'm starting to do anything like this, so I need a little bit of help to start with.

I want to print some data and give it a format to print it as an establishment ticket, so what would be the best way?

Thanks in advance.

Upvotes: 1

Views: 3178

Answers (2)

PepperBob
PepperBob

Reputation: 707

From a real live example: we're running a project that prints despatch labels to send a package with a parcel service. The label contains barcodes and other textual information as well as a logo.

Usually a ticket printer understands a special printer control language, i.e. if it's a Zebra printer it understands EPL or ZPL-code. To produce a ticket we simply send the whole control code over a simple socket connection to the printer. The control code itself is created through a template engine (Velocity in our case).

Of course there are different printers for different requirements - it may depend on what actually should be printed. So depending on the printer you may need to create a different set of template to produce your label:

https://en.wikipedia.org/wiki/Printer_control_language

By the way: Usually the printer comes with software to let you design the layout of the paper label (which makes life really easy). We used this software to create the initial layout. The control code itself contains all commands used to configure the printer (label size, etc - no doubt there are plenty of different formats and sizes, as said: it really depends on the use case).

Upvotes: 1

Michał Ziober
Michał Ziober

Reputation: 38665

If You decide to generate pdf file and then print it, I propose to use Apache FOP. I always use this library to generate PDF. This library is not easy but offers many options.

Second option - You could generate HTML page and then print it.

Upvotes: 1

Related Questions