SkillAgentSearch skills...

Printama

A very well documented android library for bluetooth thermal printer. Tested for 2 and 3 inches printers

Install / Use

/learn @anggastudio/Printama
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<div style="background-color: maroon; border-left: 12px solid #ffa500; padding: 10px; border-radius: 8px;"> <p><strong>🚀 Latest:</strong> Version 1.0.5 is now available with enhanced stability, new constant classes, and comprehensive API improvements!</p> <p><strong>✅ Recommended:</strong> Now support 3 Inches printer.</p> </div> <p align="center"> <h1 align="center">Printama</h1> <h4 align="center">🖨️ Professional Android library for Bluetooth thermal printing<br>✅ Extensively tested with 2-inch and 3-inch thermal printers<br>🎯 Built for developers who need reliable printing solutions</h4> </p> <p align="center"> <img src="https://images.unsplash.com/photo-1598346762291-aee88549193f?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80"/> </p> <p align="center"> <a href="https://jitpack.io/#anggastudio/Printama"><img src="https://jitpack.io/v/anggastudio/Printama.svg"></a> <a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/anggastudio/Printama/pulls"><img alt="Pull request" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat"></a> <a href="https://github.com/anggastudio/Printama/graphs/contributors"><img src="https://img.shields.io/github/contributors/anggastudio/Printama"></a> <a href="https://github.com/anggastudio"><img alt="Github" src="https://img.shields.io/github/followers/anggastudio?label=follow&style=social"></a> </p>

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

View on GitHub
GitHub Stars131
CategoryDevelopment
Updated2d ago
Forks37

Languages

Java

Security Score

100/100

Audited on Apr 5, 2026

No findings