All Projects → mazenrashed → Printooth

mazenrashed / Printooth

Licence: mpl-2.0
A well documented, high-level Android interface that makes printing via bluetooth printers easier

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Printooth

Gutenberg
Modern framework to print the web correctly.
Stars: ✭ 4,425 (+1815.58%)
Mutual labels:  printer, print, printing
Bashmultitool
A library for bash shell program containing useful functions. Can be imported into scripts to create colourful and functional scripts and TUIs.
Stars: ✭ 27 (-88.31%)
Mutual labels:  printer, library, print
Codeprinter
🖨️ Print out code easily
Stars: ✭ 233 (+0.87%)
Mutual labels:  printer, print, printing
Printthis
jQuery printing plugin; print specific elements on a page
Stars: ✭ 902 (+290.48%)
Mutual labels:  print, printing
Ble Indoor Positioning
Multilateration using bluetooth beacons
Stars: ✭ 274 (+18.61%)
Mutual labels:  library, bluetooth
Node Escpos
🖨️ ESC/POS Printer driver for node
Stars: ✭ 752 (+225.54%)
Mutual labels:  printer, bluetooth
nativescript-printer
📠 Send an image or the screen contents to a physical printer
Stars: ✭ 33 (-85.71%)
Mutual labels:  printer, print
Potato Library
Easy to use Utility library for Android
Stars: ✭ 45 (-80.52%)
Mutual labels:  library, bluetooth
Mapbox Gl Print Export For Port
Print/Export for Mapbox GL
Stars: ✭ 14 (-93.94%)
Mutual labels:  print, printing
React Native Esc Pos
A React Native ESC/POS module to help you connect to your ESC/POS printer easily.
Stars: ✭ 65 (-71.86%)
Mutual labels:  printer, bluetooth
Easydeviceinfo
📱 [Android Library] Get device information in a super easy way.
Stars: ✭ 1,698 (+635.06%)
Mutual labels:  library, bluetooth
printer
A fancy logger yet lightweight, and configurable. 🖨
Stars: ✭ 65 (-71.86%)
Mutual labels:  printer, print
Printerdemo
Android蓝牙连打印机
Stars: ✭ 131 (-43.29%)
Mutual labels:  printer, bluetooth
Gsm v5
gsm module library for STM32 LL
Stars: ✭ 135 (-41.56%)
Mutual labels:  library, bluetooth
Wp Print
Displays a printable version of your WordPress blog's post/page.
Stars: ✭ 16 (-93.07%)
Mutual labels:  printer, print
react-native-star-prnt
React-Native bridge to communicate with Star Micronics Bluetooth/LAN Printers
Stars: ✭ 61 (-73.59%)
Mutual labels:  printer, print
Bluetooth Library
Bluetooth client library for Android.
Stars: ✭ 172 (-25.54%)
Mutual labels:  library, bluetooth
ngx-print
🖨️ A plug n' play Angular (2++) library to print your stuff
Stars: ✭ 124 (-46.32%)
Mutual labels:  printing, print
ipp.rs
IPP protocol implementation for Rust
Stars: ✭ 24 (-89.61%)
Mutual labels:  printing, print
Cups
Apple CUPS Sources
Stars: ✭ 1,223 (+429.44%)
Mutual labels:  printer, printing

Printooth

Android Arsenal

Printooth aim is to provide a simple abstraction for use the Bluetooth printers regardless of its brand.

Add the JitPack repository to your build file

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

Add dependency

dependencies {
    implementation 'com.github.mazenrashed:Printooth:${LAST_VERSION}'
}

Add permissions to manifest

<uses-permission android:name="android.permission.BLUETOOTH" />  
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Initialize Printooth

Should be initialized once in Application.onCreate():

Printooth.init(context);

Scan and pair printer

Printooth is providing a scanning activity to make pairing process easy. Just start ScanningActivity and you will skip the process of pairing and saving printer.

startActivityForResult(Intent(this, ScanningActivity::class.java), ScanningActivity.SCANNING_FOR_PRINTER)

When the printer is being ready:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {  
    super.onActivityResult(requestCode, resultCode, data)  
    if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER && resultCode == Activity.RESULT_OK)  
        //Printer is ready now 
}

If you want to make your own user interface, you can pass your paired printer to Printooth like this:

Printooth.setPrinter(printerName, printerAddress)

Check if Printooth has saved printer:

Printooth.hasPairedPrinter()

To get the current saved printer:

Printooth.getPairedPrinter()

To remove the current saved printer:

Printooth.removeCurrentPrinter()

Printing

Printooth provides a simple builder to design your paper. To print Hello World simply, write this code:

var printables = ArrayList<Printable>()
var printable = TextPrintable.Builder()  
        .setText("Hello World")
printables.add(printable)
Printooth.printer().print(printables)

Use all builder functionalities:

var printables = ArrayList<Printable>()
var printable = TextPrintable.Builder()  
        .setText("Hello World") //The text you want to print
        .setAlignment(DefaultPrinter.ALLIGMENT_CENTER)
        .setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) //Bold or normal  
        .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
        .setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) // Underline on/off
        .setCharacterCode(DefaultPrinter.CHARACTER_CODE_USA_CP437) // Character code to support languages
        .setLineSpacing(DefaultPrinter.LINE_SPACING_60)
        .setNewLinesAfter(1) // To provide n lines after sentence
        .build()
printables.add(printable)
Printooth.printer().print(printables)

Listen to your printing order state:

Printooth.printer().printingCallback = object : PrintingCallback {  
    override fun connectingWithPrinter() { } 
  
    override fun printingOrderSentSuccessfully() { }  //printer was received your printing order successfully.
  
    override fun connectionFailed(error: String) { }  
  
    override fun onError(error: String) { }  
  
    override fun onMessage(message: String) { }  
}

Use more than printer in the same time:

var printer1 = PairedPrinter(name, address)  
var printer2 = PairedPrinter(name, address)  
Printooth.printer(printer1).print(printables)  
Printooth.printer(printer2).print(printables)

If you have a printer with deferent commands

Create a class from type Printer and override the initializers method, then return your printer commands from the printers command sheet ( You can find it on the Internet ), let's take an example:

open class MyPrinter : Printer() {  
 
   override fun initLineSpacingCommand(): ByteArray = byteArrayOf(0x1B, 0x33)  
 
   override fun initInitPrinterCommand(): ByteArray = byteArrayOf(0x1b, 0x40)  
 
   override fun initJustificationCommand(): ByteArray = byteArrayOf(27, 97)  
 
   override fun initFontSizeCommand(): ByteArray = byteArrayOf(29, 33)  
 
   override fun initEmphasizedModeCommand(): ByteArray = byteArrayOf(27, 69)
 
   override fun initUnderlineModeCommand(): ByteArray = byteArrayOf(27, 45) 
 
   override fun initCharacterCodeCommand(): ByteArray = byteArrayOf(27, 116)  
 
   override fun initFeedLineCommand(): ByteArray = byteArrayOf(27, 100)  
   
   override fun initPrintingImagesHelper(): PrintingImagesHelper = DefaultPrintingImagesHelper()
}

If you have issues with printing images, you can implement the process of transfaring image from bitmap to ByteArray manuly by extends PrintingImagesHelper class and implement getBitmapAsByteArray, then you shold return an object from your helper to initPrintingImagesHelper() as this example:

class MyPrintingImagesHelper : PrintingImagesHelper {  
    override fun getBitmapAsByteArray(bitmap: Bitmap): ByteArray {  
        return convertBitmapToByteArray(bitmap)  
    }  
}
//in your printer class
open class MyPrinter : Printer() {  
    ....
    ....
    override fun initPrintingImagesHelper(): PrintingImagesHelper = MyPrintingImagesHelper()
}
//when using printooth
private val printing = Printooth.printer(MyPrinter())
...
printing.print(printables)

Then pass your printer class to Printooth:

Printooth.printer(MyPrinter()).print(printables)

Proguard config

-keep class * implements java.io.Serializable { *; }

Contributing

We welcome contributions to Printooth!

  • ⇄ Pull requests and ★ Stars are always welcome.

Java examples

Thanks for @lafras-h for the nice project JavaPrintooth , it's an examples to use Printooth in java

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].