{"id":13463650,"url":"https://github.com/mazenrashed/Printooth","last_synced_at":"2025-03-25T09:30:58.594Z","repository":{"id":38855420,"uuid":"152863374","full_name":"mazenrashed/Printooth","owner":"mazenrashed","description":"A well documented, high-level Android interface that makes printing via bluetooth printers easier","archived":false,"fork":false,"pushed_at":"2023-07-13T07:26:36.000Z","size":270,"stargazers_count":399,"open_issues_count":61,"forks_count":113,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-29T16:19:22.652Z","etag":null,"topics":["android","android-library","bluetooth","bluetooth-printer","kotlin","kotlin-android","kotlin-library","library","pairing","print","printer","printing","sewoo","woosim"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mazenrashed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-10-13T11:00:59.000Z","updated_at":"2024-09-28T12:19:16.000Z","dependencies_parsed_at":"2023-02-01T03:45:36.894Z","dependency_job_id":"229ce175-b68b-40f5-8a6b-c971637f54c4","html_url":"https://github.com/mazenrashed/Printooth","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FPrintooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FPrintooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FPrintooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FPrintooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazenrashed","download_url":"https://codeload.github.com/mazenrashed/Printooth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435066,"owners_count":20614822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","bluetooth","bluetooth-printer","kotlin","kotlin-android","kotlin-library","library","pairing","print","printer","printing","sewoo","woosim"],"created_at":"2024-07-31T14:00:25.427Z","updated_at":"2025-03-25T09:30:57.936Z","avatar_url":"https://github.com/mazenrashed.png","language":"Kotlin","readme":"# Printooth\n[![](https://jitpack.io/v/mazenrashed/Printooth.svg)](https://jitpack.io/#mazenrashed/Printooth)\n[![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-Printooth-green.svg?style=flat )]( https://android-arsenal.com/details/1/7323 )\n\nPrintooth aim is to provide a simple abstraction for use the Bluetooth printers regardless of its brand.\n\n###  Add the JitPack repository to your build file\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n### Add dependency\n```groovy\ndependencies {\n    implementation 'com.github.mazenrashed:Printooth:${LAST_VERSION}'\n}\n```\n### Add permissions to manifest\n```groovy\n\u003cuses-permission android:name=\"android.permission.BLUETOOTH\" /\u003e  \n\u003cuses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n```\n### Initialize Printooth\nShould be initialized once in `Application.onCreate()`:\n```kotlin\nPrintooth.init(context);\n```\n### Scan and pair printer\nPrintooth is providing a scanning activity to make pairing process easy. Just start `ScanningActivity` and you will skip the process of pairing and saving printer.\n```kotlin\nstartActivityForResult(Intent(this, ScanningActivity::class.java), ScanningActivity.SCANNING_FOR_PRINTER)\n```\nWhen the printer is being ready:\n```kotlin\noverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {  \n    super.onActivityResult(requestCode, resultCode, data)  \n    if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER \u0026\u0026 resultCode == Activity.RESULT_OK)  \n        //Printer is ready now \n}\n```\nIf you want to make your own user interface, you can pass your paired printer to Printooth like this:\n```kotlin\nPrintooth.setPrinter(printerName, printerAddress)\n```\nCheck if Printooth has saved printer:\n```kotlin\nPrintooth.hasPairedPrinter()\n```\nTo get the current saved printer:\n```kotlin\nPrintooth.getPairedPrinter()\n```\nTo remove the current saved printer:\n```kotlin\nPrintooth.removeCurrentPrinter()\n```\n### Printing\nPrintooth provides a simple builder to design your paper.\nTo print `Hello World` simply, write this code:\n```kotlin\nvar printables = ArrayList\u003cPrintable\u003e()\nvar printable = TextPrintable.Builder()  \n        .setText(\"Hello World\")\n        .build()\nprintables.add(printable)\nPrintooth.printer().print(printables)\n```\nUse all builder functionalities:\n```kotlin\nvar printables = ArrayList\u003cPrintable\u003e()\nvar printable = TextPrintable.Builder()  \n        .setText(\"Hello World\") //The text you want to print\n        .setAlignment(DefaultPrinter.ALLIGMENT_CENTER)\n        .setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) //Bold or normal  \n        .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)\n        .setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) // Underline on/off\n        .setCharacterCode(DefaultPrinter.CHARACTER_CODE_USA_CP437) // Character code to support languages\n        .setLineSpacing(DefaultPrinter.LINE_SPACING_60)\n        .setNewLinesAfter(1) // To provide n lines after sentence\n        .build()\nprintables.add(printable)\nPrintooth.printer().print(printables)\n```\n### Listen to your printing order state:\n```kotlin\nPrintooth.printer().printingCallback = object : PrintingCallback {  \n    override fun connectingWithPrinter() { } \n  \n    override fun printingOrderSentSuccessfully() { }  //printer was received your printing order successfully.\n  \n    override fun connectionFailed(error: String) { }  \n  \n    override fun onError(error: String) { }  \n  \n    override fun onMessage(message: String) { }  \n}\n```\n### Use more than printer in the same time:\n```kotlin\nvar printer1 = PairedPrinter(name, address)  \nvar printer2 = PairedPrinter(name, address)  \nPrintooth.printer(printer1).print(printables)  \nPrintooth.printer(printer2).print(printables)\n```\n### If you have a printer with deferent commands\n\nCreate 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:\n ```kotlin\n open class MyPrinter : Printer() {  \n  \n    override fun initLineSpacingCommand(): ByteArray = byteArrayOf(0x1B, 0x33)  \n  \n    override fun initInitPrinterCommand(): ByteArray = byteArrayOf(0x1b, 0x40)  \n  \n    override fun initJustificationCommand(): ByteArray = byteArrayOf(27, 97)  \n  \n    override fun initFontSizeCommand(): ByteArray = byteArrayOf(29, 33)  \n  \n    override fun initEmphasizedModeCommand(): ByteArray = byteArrayOf(27, 69)\n  \n    override fun initUnderlineModeCommand(): ByteArray = byteArrayOf(27, 45) \n  \n    override fun initCharacterCodeCommand(): ByteArray = byteArrayOf(27, 116)  \n  \n    override fun initFeedLineCommand(): ByteArray = byteArrayOf(27, 100)  \n    \n    override fun initPrintingImagesHelper(): PrintingImagesHelper = DefaultPrintingImagesHelper()\n}\n```\nIf you have issues with printing images, you can implement the process of transfaring image from bitmap to ByteArray manually by extends PrintingImagesHelper class and implement getBitmapAsByteArray, then you shold return an object from your helper to initPrintingImagesHelper() as this example:\n```kotlin\nclass MyPrintingImagesHelper : PrintingImagesHelper {  \n    override fun getBitmapAsByteArray(bitmap: Bitmap): ByteArray {  \n        return convertBitmapToByteArray(bitmap)  \n    }  \n}\n//in your printer class\nopen class MyPrinter : Printer() {  \n    ....\n    ....\n    override fun initPrintingImagesHelper(): PrintingImagesHelper = MyPrintingImagesHelper()\n}\n//when using printooth\nprivate val printing = Printooth.printer(MyPrinter())\n...\nprinting.print(printables)\n```\nThen pass your printer class to Printooth:\n```kotlin\nPrintooth.printer(MyPrinter()).print(printables)\n```\n\n### Proguard config\n````\n-keep class * implements java.io.Serializable { *; }\n````\n## Contributing\n\nWe welcome contributions to Printooth!\n* ⇄ Pull requests and ★ Stars are always welcome.\n\n## Java examples\n\nThanks for @lafras-h for the nice project [JavaPrintooth](https://github.com/lafras-h/JavaPrintooth) , it's an examples to use Printooth in java\n","funding_links":[],"categories":["Android"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazenrashed%2FPrintooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazenrashed%2FPrintooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazenrashed%2FPrintooth/lists"}