MCPcopy Index your code
hub / github.com/anastaciocintra/escpos-coffee

github.com/anastaciocintra/escpos-coffee @v4.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.0 ↗ · + Follow
170 symbols 300 edges 21 files 126 documented · 74%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

escpos-coffee

Java library for ESC/POS printer commands. Can send text, images and barcodes to the printer. All commands are send to one OutputStream, then you can redirect to printer, file or network.

Wiki

GitHub Maven Central Build Status Sonatype Nexus (Snapshots)

Getting Started

The EscPos works with OutputStream to send its commands. Here we have two examples that show different output streams.

Creating printer output stream:

  PrintService printService = PrinterOutputStream.getPrintServiceByName("printerName");
  PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
  EscPos escpos = new EscPos(printerOutputStream);
  escpos.writeLF("Hello Wold");
  escpos.feed(5);
  escpos.cut(EscPos.CutMode.FULL);
  escpos.close();

Sending hello world to system out:

  EscPos escpos = new EscPos(System.out);
  escpos.writeLF("Hello Wold");
  escpos.feed(5);
  escpos.cut(EscPos.CutMode.FULL);
  escpos.close();

See on samples directory to view more codes.

Downloading

Download code and binaries from the last release of escpos-coffee.

Installation with Maven

<dependency>
  <groupId>com.github.anastaciocintra</groupId>
  <artifactId>escpos-coffee</artifactId>
  <version>4.1.0</version>
</dependency>

Installation with Gradle

Step 1. Add the repository to your build file

repositories {
    mavenCentral()
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.anastaciocintra:escpos-coffee:4.1.0'
}

Installation without Maven or Gradle

The project can be compiled with the below command:


./mvnw clean package

Then the jar file will be generated inside the 'target/' folder, just add the jar file to your classpath.

Samples

You can find all samples codes on https://github.com/anastaciocintra/escpos-coffee-samples

getstart sample

getstart - Send info of the library to the printer.

output

textstyle sample

textstyle - Shows how to construnct one simple receipt.

output

Also this sample show how simple is to create diferent text styles, like title, subtitle, bold, etc.

  Style title = new Style()
          .setFontSize(Style.FontSize._3, Style.FontSize._3)
          .setJustification(EscPosConst.Justification.Center);

graphicsimage, bitimage and rasterimage samples

Shows how to work with ImageWrapper.

Then you will see things like how to print on center-justified one image, like this:

    escpos.writeLF("print on Center");
    imageWrapper.setJustification(EscPosConst.Justification.Center);
    escpos.write(imageWrapper, escposImage);

dithering sample

dithering - Shows how to work with BitonalThreshold and BitonalOrderedDither.

output

output

Bellow, we can see how to use ordered dither class.

  algorithm = new BitonalOrderedDither();
  EscPosImage escposImage = new EscPosImage(new CoffeeImageImpl(imageBufferedImage), algorithm);     
  escpos.write(imageWrapper, escposImage);

barcode sample

barcode - Shows barcode, PDF417 and qrcode.

output

output

output

Bellow, code to send barcode to the printer

  BarCode barcode = new BarCode();
  escpos.write(barcode, "hello barcode");

codetable sample

charcode - Shows how to send texts from different languages.

  escpos.setCharacterCodeTable(CharacterCodeTable.CP863_Canadian_French);
  escpos.writeLF("Liberté et Fraternité.");

Others

Android - How to use this lib on Android Studio project.

BarcodeGen - How to generate barcode image and print it

PdfPrinting - How to print pdf files

CoffeeBitmap - How to construct html/css receipts

output

Versioning

Using SemVer for versioning.

Lastest release here.

Contributting

Contributors are welcome, but before you do it its important to read and agree with CODE_OF_CONDUCT.md and CONTRIBUTING.md.

Acknowledgments

I would like to thanks Michael Billington and contributors for the great work on the mike42/escpos-php project that inspired me to start this project.

Extension points exported contracts — how you extend this code

EscPosConst (Interface)
(no doc) [9 implementers]
src/main/java/com/github/anastaciocintra/escpos/EscPosConst.java
ImageWrapperInterface (Interface)
(no doc) [9 implementers]
src/main/java/com/github/anastaciocintra/escpos/image/ImageWrapperInterface.java
BarCodeWrapperInterface (Interface)
(no doc) [9 implementers]
src/main/java/com/github/anastaciocintra/escpos/barcode/BarCodeWrapperInterface.java
CoffeeImage (Interface)
Specify the interface to work with image @see CoffeeImageImpl @see <a href="https://github.com/anastaciocintra/AdroidEsc [2 …
src/main/java/com/github/anastaciocintra/escpos/image/CoffeeImage.java

Core symbols most depended-on inside this repo

write
called by 250
src/main/java/com/github/anastaciocintra/escpos/EscPos.java
getWidth
called by 8
src/main/java/com/github/anastaciocintra/escpos/image/CoffeeImage.java
getHeight
called by 7
src/main/java/com/github/anastaciocintra/escpos/image/CoffeeImage.java
writeLF
called by 4
src/main/java/com/github/anastaciocintra/escpos/EscPos.java
getBytes
called by 4
src/main/java/com/github/anastaciocintra/escpos/image/ImageWrapperInterface.java
getBytes
called by 4
src/main/java/com/github/anastaciocintra/escpos/barcode/BarCodeWrapperInterface.java
feed
called by 3
src/main/java/com/github/anastaciocintra/escpos/EscPos.java
getConfigBytes
called by 3
src/main/java/com/github/anastaciocintra/escpos/Style.java

Shape

Method 130
Enum 19
Class 17
Interface 4

Languages

Java100%

Modules by API surface

src/main/java/com/github/anastaciocintra/escpos/EscPos.java25 symbols
src/main/java/com/github/anastaciocintra/escpos/Style.java20 symbols
src/main/java/com/github/anastaciocintra/escpos/barcode/PDF417.java14 symbols
src/main/java/com/github/anastaciocintra/escpos/barcode/BarCode.java14 symbols
src/main/java/com/github/anastaciocintra/escpos/image/EscPosImage.java11 symbols
src/main/java/com/github/anastaciocintra/escpos/barcode/QRCode.java11 symbols
src/main/java/com/github/anastaciocintra/escpos/PrintModeStyle.java11 symbols
src/main/java/com/github/anastaciocintra/escpos/image/RasterBitImageWrapper.java7 symbols
src/main/java/com/github/anastaciocintra/escpos/image/GraphicsImageWrapper.java7 symbols
src/main/java/com/github/anastaciocintra/escpos/image/BitImageWrapper.java7 symbols
src/main/java/com/github/anastaciocintra/output/PrinterOutputStream.java6 symbols
src/main/java/com/github/anastaciocintra/escpos/image/CoffeeImageImpl.java6 symbols

For agents

$ claude mcp add escpos-coffee \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page