Skip to content

Text Styles

Marco Antonio edited this page Dec 4, 2021 · 2 revisions

Style class

You can configure:

  • Font
  • Bold - yes/no
  • Underline
  • FontSize
  • Justification
  • ColorMode

Creating your own styles

First, pre-configure your text styles to use:

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

Style subtitle = new Style(escpos.getStyle())
        .setBold(true)
        .setUnderline(Style.Underline.OneDotThick);
Style bold = new Style(escpos.getStyle())
        .setBold(true);

Using pre-configured styles

After configure your styles, you can easily use it:

escpos.writeLF(title,"My Market")
        .feed(3)
        .write("Client: ")
        .writeLF(subtitle, "John Doe")
        .feed(3)
        .writeLF("Cup of coffee                      $1.00")
        .writeLF("Botle of water                     $0.50")
        .writeLF("----------------------------------------")
        .feed(2)
        .writeLF(bold, 
                 "TOTAL                              $1.50")
        .writeLF("----------------------------------------")
        .feed(8)
        .cut(EscPos.CutMode.FULL);

complete code

Working directly with default style of EscPos class:

Style style = escpos.getStyle();
style.setBold(true);
escpos.writeLF("hello bold");
escpos.getStyle().setBold(false).setUnderline(Style.Underline.OneDotThick);
escpos.writeLF("Hello Underline");
escpos.feed(5).cut(EscPos.CutMode.FULL);
escpos.close();

PrintModeStyle (plan B)

If your printer isn't compatible with Style commands, alternativelly, you can try to use the PrintModeStyle, but it doesn't have all features of Style.

PrintModeStyle normal = new PrintModeStyle();
escpos.writeLF(normal,"hello normal PrintModeStyle");
PrintModeStyle rightBold = new PrintModeStyle().setBold(true).setJustification(EscPosConst.Justification.Right);
escpos.writeLF(rightBold,"Right bold");
escpos.feed(5).cut(EscPos.CutMode.FULL);
escpos.close();

PrintModeStyle sample