+
Skip to content

anggastudio/Printama

Repository files navigation

🚀 Latest: Version 0.9.80 is now available with enhanced column formatting and improved stability!

✅ Recommended: Use 0.9.80 for the best experience across all Android versions.

✅ Recommended: Now support 3 Inches printer.

📱 Compatibility: Supports Android 13+ with optimized Bluetooth permissions.

⚠️ Deprecated: Versions 0.9.71 and 0.9.72 are no longer supported.

Printama

🖨️ Professional Android library for Bluetooth thermal printing
✅ Extensively tested with 2-inch and 3-inch thermal printers
🎯 Built for developers who need reliable printing solutions

License Pull request Github

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 0.9.80:

  • 🆕 Advanced column formatting (2-5 columns)
  • 🔧 Improved text alignment and spacing
  • 📱 Enhanced Android 13+ compatibility
  • 🎨 Better receipt layout capabilities

Basic Setup

Permissions in your Manifest

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"  android:usesPermissionFlags="neverForLocation"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

Permission check in your Activity. Call checkPermissions() in your onCreate() method

private static String[] PERMISSIONS_STORAGE = {
    Manifest.permission.READ_EXTERNAL_STORAGE,
    Manifest.permission.WRITE_EXTERNAL_STORAGE,
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.ACCESS_COARSE_LOCATION,
    Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
    Manifest.permission.BLUETOOTH_SCAN,
    Manifest.permission.BLUETOOTH_CONNECT,
    Manifest.permission.BLUETOOTH_PRIVILEGED
};

private static String[] PERMISSIONS_LOCATION = {
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.ACCESS_COARSE_LOCATION,
    Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
    Manifest.permission.BLUETOOTH_SCAN,
    Manifest.permission.BLUETOOTH_CONNECT,
    Manifest.permission.BLUETOOTH_PRIVILEGED
};

private void checkPermissions() {
    int permission1 = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permission2 = ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN);

    if (permission1 != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(
                this,
                PERMISSIONS_STORAGE,
                1
        );
    } else if (permission2 != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                PERMISSIONS_LOCATION,
                1
        );
    }
}

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(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();
});

🆕 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"), Printama.LEFT);
    printama.printTextln(printama.formatTwoColumns("Coffee", "$3.50"), Printama.LEFT);
    
    // Three columns with default widths (50% - 20% - 30%)
    printama.printTextln(printama.formatThreeColumns("Item", "Qty", "Total"), Printama.LEFT);
    printama.printTextln(printama.formatThreeColumns("Espresso", "2", "$7.00"), Printama.LEFT);
    
    // Four columns with default widths (40% - 20% - 20% - 20%)
    printama.printTextln(printama.formatFourColumns("ID", "Name", "Stock", "Price"), Printama.LEFT);
    printama.printTextln(printama.formatFourColumns("001", "Coffee", "50", "$3.50"), Printama.LEFT);
    
    // Five columns with default widths (30% - 20% - 20% - 15% - 15%)
    printama.printTextln(printama.formatFiveColumns("ID", "Item", "Cat", "Qty", "$"), Printama.LEFT);
    
    // Custom column widths (percentages must sum to 100)
    double[] customWidths = {60.0, 40.0}; // 60% - 40%
    printama.printTextln(printama.formatTwoColumns("Description", "Amount", customWidths), Printama.LEFT);
    
    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 a parameter:

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

Features

🔧 Core Printing Capabilities

  • Text Alignment: LEFT, CENTER, RIGHT, and JUSTIFY alignment options
  • Image Printing: Auto-grayscale bitmap printing with custom width and alignment
  • Photo Printing: High-quality grayscaled photo output
  • Layout Printing: Print Android views and layouts directly
  • Vector Support: Print vector drawables with perfect scaling

🆕 Advanced Formatting (v0.9.80)

  • Column Formatting: Smart 2-5 column layouts with automatic width calculation
  • Custom Widths: Flexible column width percentages for precise control
  • Text Overflow: Automatic text truncation to prevent layout breaks
  • Adaptive Sizing: Auto-adjusts for 2-inch and 3-inch printer compatibility

📱 Device & Connectivity

  • Bluetooth Integration: Seamless pairing with bonded device selection dialog
  • Custom UI: Customizable printer selection dialog colors
  • Wide Compatibility: Extensively tested with 2-inch and 3-inch thermal printers
  • Android 13+ Ready: Optimized for latest Android versions with proper permissions

🎨 Text Styling Options

  • Font Sizes: Small, normal, tall, and wide text variants
  • Text Effects: Bold, underline, and strikethrough formatting
  • Line Spacing: Customizable spacing for better receipt layout
  • Mixed Formatting: Combine multiple text styles in single print job

Contributing

You can simply :

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

Download

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 {
  ... 
  #groovy
  implementation 'com.github.anggastudio:Printama:<version>'
  #kts
  implementation("com.github.anggastudio:Printama:<version>")
  ...
}

Other like Maven, SBT, Leiningen:

just visit the jitpack page click here -->

License

Apache License 2.0

Thanks To:

Roadmap

🎯 Version 1.0.0 (Coming Soon)

  • Stability Focus: Comprehensive testing and bug fixes
  • Documentation: Complete API documentation and guides
  • Video Tutorials: Step-by-step implementation tutorials
  • Kotlin Migration: Modern Kotlin-first API design

🔮 Future Enhancements

  • 3-inch Printer Optimization: Enhanced support for wider thermal printers
  • Multi-Brand Testing: Expanded compatibility testing across printer manufacturers
  • Advanced Layouts: Template-based receipt designs
  • Performance Optimization: Faster printing and reduced memory usage
  • Cloud Integration: Remote printing capabilities

📈 Recent Achievements (v0.9.80)

  • ✅ now support 3 Inches printer
  • ✅ Advanced column formatting system
  • ✅ Improved Android 13+ compatibility
  • ✅ Enhanced text alignment and spacing
  • ✅ Better error handling and stability

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载