Skip to content

A very well documented android library for bluetooth thermal printer. Tested for 2 inch printers

License

Notifications You must be signed in to change notification settings

imnadev/Printama

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Printama

Android library for bluetooth thermal printer.
Tested to many 2 inch bluetooth thermal printers.

License Pull request Twitter Github

Screenshots

Payment Receipt Print Text and Images
Photo Photo Print Result
Screen Layout Screen Layout Print Result

Usage

Currently still in Alpha. Make sure to use java 8+ configuration. Documentation is in progress. Just take a look at sample project as an example.

But here for an insight:

Show dialog to choose bonded device (printer list) bind your device initially from the bluetooth config:

Printama.showPrinterList(this, printerName -> {
    ...
});

Show dialog to choose bonded device (Custom Color)

Printama.showPrinterList(this, R.color.colorBlue, printerName -> {
    if (connectedPrinter != null) {
      ...
    }
});

Prepare the text

String text = "-------------\n" +
                "This will be printed\n" +
                "Left aligned\n" + // or Center or Right
                "cool isn't it?\n" +
                "------------------\n";

Print Text LEFT aligned

Printama.with(context).connect(printama -> {
    printama.printText(Printama.LEFT, text);
    printama.close();
});

Print Text CENTER aligned

Printama.with(context).connect(printama -> {
    printama.printText(Printama.CENTER, text);
    printama.close();
});

Print Text RIGHT aligned

Printama.with(context).connect(printama -> {
    printama.printText(Printama.RIGHT, text);
    printama.close();
});

Print Text JUSTIFY aligned

Printama.with(this).connect(printama -> {
    printama.printTextJustify("text1", "text2");
    printama.printTextJustify("text1", "text2", "text3");
    printama.printTextJustify("text1", "text2", "text3", "text4");

    printama.printTextJustifyBold("text1", "text2");
    printama.printTextJustifyBold("text1", "text2", "text3");
    printama.printTextJustifyBold("text1", "text2", "text3", "text4");

    printama.setNormalText();
    printama.feedPaper();
    printama.close();
});

Print Text with format

Printama.with(this).connect(printama -> {
    printama.setSmallText();
    printama.printText("small___________");
    printama.printTextln("TEXTtext");

    printama.setNormalText();
    printama.printText("normal__________");
    printama.printTextln("TEXTtext");

    printama.printTextNormal("bold____________");
    printama.printTextlnBold("TEXTtext");

    printama.setNormalText();
    printama.printTextNormal("tall____________");
    printama.printTextlnTall("TEXTtext");

    printama.printTextNormal("tall bold_______");
    printama.printTextlnTallBold("TEXTtext");

    printama.printTextNormal("wide____________");
    printama.printTextlnWide("TEXTtext");

    printama.printTextNormal("wide bold_______");
    printama.printTextlnWideBold("TEXTtext");

    printama.printTextNormal("wide tall_______");
    printama.printTextlnWideTall("TEXTtext");

    printama.printTextNormal("wide tall bold__");
    printama.printTextlnWideTallBold("TEXTtext");

    printama.printTextNormal("underline_______");
    printama.setUnderline();
    printama.printTextln("TEXTtext");

    printama.printTextNormal("delete line_____");
    printama.setDeleteLine();
    printama.printTextln("TEXTtext");

    printama.setNormalText();
    printama.feedPaper();
    printama.close();
});

Print Bitmap / Image LEFT aligned

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Printama.with(context).connect(printama -> {
    printama.printImage(Printama.LEFT, bitmap, 200);
    printama.close();
});

Print Bitmap / Image CENTER aligned

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Printama.with(context).connect(printama -> {
    printama.printImage(Printama.CENTER, bitmap, 200);
    printama.close();
});

Print Bitmap / Image RIGHT aligned

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Printama.with(context).connect(printama -> {
    printama.printImage(Printama.RIGHT, bitmap, 200);
    printama.close();
});

Print Bitmap / Image FULL size

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Printama.with(context).connect(printama -> {
    printama.printImage(bitmap, Printama.FULL_WIDTH);
    printama.close();
});

Print Bitmap / Image ORIGINAL size

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Printama.with(context).connect(printama -> {
    printama.printImage(bitmap); // original size, centered as default
    printama.close();
});

Print Drawable Vector

Bitmap bitmap = Printama.getBitmapFromVector(this, R.drawable.ic_launcher_background);
Printama.with(this).connect(printama -> {
    printama.printImage(bitmap, Printama.ORIGINAL_WIDTH);
    printama.close();
});

Print Layout View

using print layout view, you can design your receipt on your layout xml or dsl, and pass the root view as parameter

View view = findViewById(R.id.root_view);
Printama.with(this).connect(printama -> {
    printama.printFromView(view);
    printama.close();
});

Feature

  • Dialog to choose bonded bluetooth device list.
  • Print Text with LEFT, CENTER, or RIGHT Alignment.
  • Print Text with JUSTIFY Alignment.
  • Print auto grayscale Bitmap with Custom width and Alignment.
  • Print photo (grayscaled)
  • Print your android screen or layout by passing the root view
  • Print vector drawable
  • Tested with 2 inch Bluetooth Thermal Printers.

Contributing

You can simply :

  • a pull request, or
  • raise an issue ticket, or
  • request additional feature by raise a ticket.

Download

Minimum Android SDK Version 16

Gradle

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2. Add the dependency

version:

dependencies {
  implementation 'com.github.imnadev:Printama:<version>'

Other like Maven, SBT, Leiningen

just visit the jitpack page Printama Jitpack

License

Apache License 2.0

Thanks To:

Next Step:

  • release 1.0.0 to make it more stable
  • enhance documentation
  • create a video tutorial
  • testing on more printers
  • (still in my mind) migrate to kotlin

Support me:

I notice that some of you very happy with this library and some of you wants to give support. But I also notice some of you wants to support me anonymously. Well then, I appreciate if you want to support me by sending some ETH or BNB via these wallet addresses:

  • 0x2fB5BF149Ac0765b546DB4feD3E64FBF9f14eb8a
  • 0x7A65cc9d8031f67847662cC92Fa93b71dCc95605

About

A very well documented android library for bluetooth thermal printer. Tested for 2 inch printers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%