Package io.github.chkrishnatej.rp3200


package io.github.chkrishnatej.rp3200
Receipt printing for the TVS RP 3200 Lite (and other ESC/POS thermal printers) from a Java server - typically a Spring Boot web application.

The library only produces bytes. It has no dependencies, does no I/O and never talks to a printer. The bytes are sent to the browser, which forwards them to the small rp3200-agent running on the shop PC that has the USB printer:

 Spring Boot + rp3200-core  --bytes-->  browser (rp3200-print.js)  --HTTP-->  rp3200-agent (127.0.0.1:9632)  --USB-->  printer
 

Two ways to describe a receipt

APIs
APIUse when
ReceiptTemplate the layout lives in a text file (src/main/resources/receipts/*.txt) and is filled with data - recommended for bills, KOTs, tokens
EscPosBuilder the receipt is assembled in Java code, or a template needs dynamic extras

Both produce identical bytes for the same layout and can be mixed with ReceiptTemplate.renderInto(EscPosBuilder, Object).

Quick start


 // 1. Template (compile once, e.g. as a Spring bean)
 ReceiptTemplate bill = ReceiptTemplate.fromClasspath("receipts/bill.txt");
 byte[] bytes = bill.render(data, PrinterProfile.RP3200_80MM);

 // 2. Builder
 byte[] bytes = new EscPosBuilder(PrinterProfile.RP3200_80MM)
         .center().bold(true).line("MY SHOP").bold(false)
         .left().row(Columns.parse("*,10r"), "Tea x2", "40.00")
         .cut()
         .build();
 

Browser side

The jar also contains META-INF/resources/rp3200/rp3200-print.js, which Spring Boot serves automatically at /rp3200/rp3200-print.js:


 <script src="/rp3200/rp3200-print.js"></script>
 <script>
   const printer = new RP3200Printer();                  // agent on http://127.0.0.1:9632
   await printer.printFromUrl('/api/bills/42/receipt');   // GET bytes from your server, print them
 </script>
 

Types in this package

Remote monitoring

rp3200-print.js can post the agent's health to your server; bind it with the records in io.github.chkrishnatej.rp3200.health (PrinterHealthReport, AgentStatus).

Requires Java 17 or newer. All types are either immutable and thread-safe (PrinterProfile, Columns, Style, ReceiptTemplate) or meant for one receipt on one thread (EscPosBuilder).

  • Class
    Description
    Horizontal alignment of a printed line (ESC/POS command ESC a n).
    A column layout for table-like rows such as Item | Qty | Amount.
    Fluent builder that produces the raw ESC/POS bytes for one receipt.
    Describes the physical printer: how many characters fit on a line and how text is encoded.
    Character style: bold, underline, reverse (white on black) and size.
    A run of text printed in one style - the building block of mixed-style table cells.
    Character magnification (ESC/POS command GS ! n).