android 打印机有开放的库吗,一个非常完善的Android库,用于蓝牙热敏打印机

Printama

Android library for bluetooth thermal printer.

6ba0789864ea54423ac5d6f21619cad4.png63a47a1f250cdfdfd7a936cb664b2f8b.png4adff618aa2d11791ac334bfff5469d6.pngb17d5aa1279e36bdcba61db4a6b3c5f1.pngrose_print.jpeg52a09714bd311d4ea1995aa4ecce5e24.png52e37b980eb14c625280a0a50f350c29.png

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 bind your device initially from the bluetooth config:

Printama.showPrinterList(this, printerName -> {

...

});

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 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 Custom 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

dependencies {

implementation 'com.github.anggastudio:Printama:0.8.5'

}

Other like Maven, SBT, Leiningen

just visit the jitpack page Printama Jitpack

License

Thanks To:

Contributor:

you (maybe)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值