Printama
A very well documented android library for bluetooth thermal printer. Tested for 2 and 3 inches printers
Install / Use
/learn @anggastudio/PrintamaREADME
Screenshots
|Payment Receipt|Print Text and Images|
|---|---|
|
|
|
|Photo|Photo Print Result|
|---|---|
|
|
|
|Screen Layout|Screen Layout Print Result|
|---|---|
|
|
|
💝 Support the Project
Printama saves developers countless hours with reliable printing solutions. Your support helps us expand compatibility and maintain this free resource.
🚀 How Your Support Helps
- Hardware Acquisition: Purchase various printer models for testing
- Continuous Testing: Ensure compatibility across different brands
- Development Time: Maintain and improve the library
- Documentation: Create better guides and tutorials
☕ Contribute Via
|Platform|Link|Features| |---|---|---| |PayPal|Donate via PayPal|Secure, worldwide| |Ko-fi|Support on Ko-fi|Coffee-themed, easy| |Buy Me a Coffee|Buy Me a Coffee|Popular, anonymous option| |Trakteer|Trakteer (ID)|Indonesian platform| |Saweria|Saweria (ID)|Indonesian platform| |USDT (BEP20)|Pay via Trust Wallet|Crypto, decentralized|
💰 USDT Donation Details
Network: BEP20 (Binance Smart Chain)
Address:
0x7A65cc9d8031f67847662cC92Fa93b71dCc95605
- With Trust Wallet: Click the USDT link above to open Trust Wallet directly
- Manual Transfer: Copy the address above and send USDT via any BEP20-compatible wallet
💡 Tip: The library includes a beautiful donation screen in the sample app!
Quick Start
Requirements:
- Android SDK 16+
- Java 8+ configuration
- Bluetooth thermal printer (2-inch or 3-inch)
Latest Features in 1.0.0:
- 🆕 New constant classes (PA, PW) for better organization
- 🔧 Improved method parameter order for consistency
- 📱 Enhanced Android 13+ compatibility
- 🎨 Advanced column formatting (2-5 columns)
- 🛡️ Comprehensive stability improvements
- 📚 Complete API documentation
- 🔧 Improved text alignment and spacing
- 🎨 Better receipt layout capabilities
Basic Setup
Permissions in your Manifest
For Android 12 (API 31) and higher:
<!-- Bluetooth permissions for Android 12+ -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="31" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Legacy Bluetooth permissions for older devices -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Location permission for Bluetooth scanning on older devices -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30" />
<!-- Hardware features (optional) -->
<uses-feature android:name="android.hardware.bluetooth"
android:required="false" />
<uses-feature android:name="android.hardware.bluetooth_le"
android:required="false" />
Permission handling in your Activity
Add this permission request constant:
private final int PERMISSION_REQUEST_BLUETOOTH_CONNECT = 432;
Check and request permissions in your Activity:
private void checkBluetoothPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
// Permission granted - proceed with printer operations
connectToPrinter();
} else {
// Request permissions
requestBluetoothPermission();
}
}
private void requestBluetoothPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Android 12+ - Request new Bluetooth permissions
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT
},
PERMISSION_REQUEST_BLUETOOTH_CONNECT);
} else {
// Older Android versions - Request Bluetooth enable
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, PERMISSION_REQUEST_BLUETOOTH_CONNECT);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_BLUETOOTH_CONNECT) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted
connectToPrinter();
} else {
// Permission denied
Toast.makeText(this, "Bluetooth permission is required for printing", Toast.LENGTH_LONG).show();
}
}
}
Call permission check in your onCreate() method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Check permissions when activity starts
checkBluetoothPermission();
}
Show dialog to choose bonded device (printer list) bind your device initially from the bluetooth config:
Printama.showPrinterList(this, printerName -> {
// Your code here
});
Show dialog to choose bonded device (Custom Color)
Printama.showPrinterList(this, R.color.colorBlue, printerName -> {
if (connectedPrinter != null) {
// Your code here
}
});
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(text, PA.LEFT);
printama.close();
});
Print Text CENTER aligned
Printama.with(context).connect(printama -> {
printama.printText(text, PA.CENTER);
printama.close();
});
Print Text RIGHT aligned
Printama.with(context).connect(printama -> {
printama.printText(text, PA.RIGHT);
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();
});
🆕 Advanced Column Formatting (New in 0.9.80)
Printama now includes powerful column formatting methods that automatically handle width calculation and text alignment:
Printama.with(this).connect(printama -> {
// Two columns with default widths (70% - 30%)
printama.printTextln(printama.formatTwoColumns("Product", "Price"), PA.LEFT);
printama.printTextln(printama.formatTwoColumns("Coffee", "$3.50"), PA.LEFT);
// Three columns with default widths (50% - 20% - 30%)
printama.printTextln(printama.formatThreeColumns("Item", "Qty", "Total"), PA.LEFT);
printama.printTextln(printama.formatThreeColumns("Espresso", "2", "$7.00"), PA.LEFT);
// Four columns with default widths (40% - 20% - 20% - 20%)
printama.printTextln(printama.formatFourColumns("ID", "Name", "Stock", "Price"), PA.LEFT);
printama.printTextln(printama.formatFourColumns("001", "Coffee", "50", "$3.50"), PA.LEFT);
// Five columns with default widths (30% - 20% - 20% - 15% - 15%)
printama.printTextln(printama.formatFiveColumns("ID", "Item", "Cat", "Qty", "$"), PA.LEFT);
//
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
