mazenrashed / printooth Goto Github PK
View Code? Open in Web Editor NEWA well documented, high-level Android interface that makes printing via bluetooth printers easier
License: Mozilla Public License 2.0
A well documented, high-level Android interface that makes printing via bluetooth printers easier
License: Mozilla Public License 2.0
Is possible to print from Recyclerview? How its work?
With the migration to androidx, the lib must be imported in build.gradle (:app):
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
Because, the Android Studio get this error:
[+] android.view.InflateException: Binary XML file line #15: Error inflating class androidx.swiperefreshlayout.widget.SwipeRefreshLayout.
[+] java.lang.ClassNotFoundException: Didn't find class "androidx.swiperefreshlayout.widget.SwipeRefreshLayout"
So, as in ScanningActivity.kt don't have this import:
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
We have to import that in our gradle file =D
I'm trying to print image with center alignment, but whatever alignment I set on my ImagePrintable, the image result is always aligning to the left, while the TextPrintable alignment works just as intended.
Is there anything else that I should add to my code to make the image appear on the center?
Here's my code:
ArrayList<Printable> al = new ArrayList<>();
Resources resources = getResources();
Bitmap image = BitmapFactory.decodeResource(resources,R.drawable.logo);
al.add(new ImagePrintable.Builder(image)
.setAlignment(DefaultPrinter.Companion.getALIGNMENT_CENTER())
.setNewLinesAfter(1)
.build());
al.add( (new TextPrintable.Builder())
.setText(" Hello World")
.setAlignment(DefaultPrinter.Companion.getALIGNMENT_CENTER())
.setNewLinesAfter(1)
.build());
printing.print(al);
Hi,
I'm doing logo for open source projects. When I was doing research at Github, I saw your project. If you want, we can design a logo according to your wishes.
cheers.
Hello this library is great! Is it possible to print HTML?
package com.mazenrashed.printooth.data.converter
Could you change
fun toByteArray(input: String): ByteArray {...}
to
open fun toByteArray(input: String): ByteArray {...}
I need it to use multibyte encoding, such as UTF-8
Thank you for this great lib
I am getting this error
Binary XML file line #16 in com.genericprinter.ca:layout/activity_scanning: Error inflating class androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Ive tried on POS printer its responding and connected but not print the data. Any help?
Hi.
I have a problem. I Can not print character Unicode. Please help me
Example: ê, ề, ế, ệ, ễ, ể
Thanks
how to set font smaller than DefaultPrinter.FONT_SIZE_NORMAL
?
0x00
is normal
0x10
is large
how much for smaller than normal?
Everything Working Fine but i want reduce less than getLINE_SPACING_30. how i can do it?
unable to find value of variable LAST_VERSION in
implementation 'com.github.mazenrashed:Printooth:${LAST_VERSION}'
I am currently unable to add library because I do not know the version of library.
Hi,
How i said in the title, i implement the printooth code to print in my android studio app, i follow every step but when i go to print, the printer roll out the blank white paper but dont write anything.
How can i solve? i try different printer but still the same problem
Hi , can you add auto reconnect feature to this library ?
Or can you point me into right direction so that i can write it ?
project cannot import Printing if I write this import com.mazenrashed.printooth.utilities.Printing; Main activity red line Printing
Salam mazin,
is this lib support barcode printing ?
Thanks in advance
Thank you for this awesome library @mazenrashed . Is there a way I can check if the last paired printer is active. Something like an isConnected()
call.
Is there a way I can do this before attempting to print?
Respected Developer,
First of all i want to say thank you to you for this easy to use library. I want to know, how we can print images or QR code using this library ?
hi,can print pdf file?
Hi, nice library easy to use. Can I print a bitmap? I'll create a bitmap in my application, but your PrintableBuilder can only send resources from application.
Hi,
Thanks for this library. I set it up on my Android project and successfully printing English characters. How can I sen another code page encoding?
I' ve seen on DefaultPrinter.kt how you define some Byte
vars like CHARACTER_CODE_ARABIC_CP720
.
How can I define for a different Language other than Arabic or English?
Thank you in advance
android.support.v4.widget.SwipeRefreshLayout changed to => androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Hi!, I'm using this great lib with java and androidx. But when I try to open intent ScanningActivity I get this error.....
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.mazenrashed.printooth.ui.ScanningActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.swiperefreshlayout.widget.SwipeRefreshLayout" on path: DexPathList[[zip file "/data/app/com.example.myapplication-ij5HA_Uou0mV2FSe1dg4sg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-ij5HA_Uou0mV2FSe1dg4sg==/lib/arm64, /system/lib64, /vendor/lib64]]
When I print no text appears when the paper comes out of the printer. What could be the problem?
Printing Images doesn't work. And when i try make MyPrinter class than implements Printer, It says that must include useConverter method. Could you tell me more about the method
override fun useConverter(): Converter {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
I saw in one example that you were using ArabicConverter. How to write converter for Russian/Cyrillic converter? Setting character code doesn't help...
I am using oneplus 5 goojprt recipet printer. But no response from printer.
I am trying to print a receipt that's longer than 4 feet, but it's not working.
it prints about about 3 feet then stop with a red bulb on the printer.
could you tell me how to resovle this issue ?
Hi, I have a list of items with a button which I can press and print the item info. Printing is fine if I press a button and wait for a while until I press again another one. But if I press two buttons too close in time I get this error and it prints only the first one:
W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@a1962b9, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@cf996fe, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@8bade5fmSocket: android.net.LocalSocket@3cbd0ac impl:android.net.LocalSocketImpl@8647175 fd:java.io.FileDescriptor@2d4250a, mSocketState: INIT D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@a1962b9, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@cf996fe, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@8bade5fmSocket: null, mSocketState: CLOSED read failed, socket might closed or timeout, read ret: -1
I just have a clickListener for the buttons:
binding.button.setOnClickListener {
Printer.print(organisationName, item)
viewModel.editOrderStatus(item.id, item.statusId+1)
}
fun print(organisationName: String, order: Order) {
if (Printooth.hasPairedPrinter()) {
var printables = ArrayList<Printable>()
var printable = TextPrintable.Builder()
.setText(organisationName) //The text you want to print
.setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
.setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_BOLD) //Bold or normal
.setFontSize(DefaultPrinter.FONT_SIZE_LARGE)
.setUnderlined(DefaultPrinter.UNDERLINED_MODE_ON) // Underline on/off
.setCharacterCode(DefaultPrinter.CHARCODE_PC437) // 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)
}
}
Any workaround I can have here?
Thanks!
Hi,
I was trying Printooth in a proyect I'm working on. I was able to use the library with a bluetooth printer, but there is a problem. My code schedules to reset ( off /on) the bluetooth after a few minutes and, if I've printed something before, my printer prints again the same thing without sending the order.
This are the steps of the code:
I don't know if is an issue with the library that doesn't close the BT conection or It's just my printer that has this behaviour.
Here is the code of the printing scenario:
` PairedPrinter printer = Printooth.INSTANCE.getPairedPrinter();
ArrayList<Printable> printables = new ArrayList<>();
Printable printable = new TextPrintable.Builder()
.setText("Hello World" )
.build();
printables.add(printable);
Printooth.INSTANCE.printer().print(printables);
`
Thanks in advance.
I developed an app using Printooth, everything is fine when the printer is in ESC/POS mode, but if I switch the printer's configuration to TPCL or RCT (for label paper feed control) it looks like my app send the command, the printer sign as receiving the command, but just doesn't print.
If anyone have ever developed Android App for Thermal label printer, please share your experience.
Hi. For Apps targetting API 28 they need to declare location permissions
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
to be able to scan for devices. If app has not requested this permisson the ScanningActivity can only see already paired devices.
This permission can be included in the app or somewhere in the ReadMe
Hi,
When initiating the intent for Scanning Acitivty. Is it only supposed to show a list of devices that have been previously paired in the past or is it suppose to show all the list of devices.
Here is my java code
Intent scanDeviceIntent = new Intent(this, ScanningActivity.class);
startActivityForResult(scanDeviceIntent, ScanningActivity.SCANNING_FOR_PRINTER);
@OverRide
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER && resultCode == Activity.RESULT_OK) {
Log.e(TAG, "Scan completed:: ");
PairedPrinter pairedDevices = Printooth.INSTANCE.getPairedPrinter();
Log.i(TAG, "name: " + pairedDevices.getName());
TextView printerName = (TextView) findViewById(R.id.printerName);
printerName.setText(pairedDevices.getName());
}
}
In the list of devices, I cannot see any devices even though bluetooth is on for other devices around
this problem was triggered when user tries to select a bluetooth device during the scan.
It looks like you forgot to call unregisterReceiver().
Activity com.mazenrashed.printooth.ui.ScanningActivity has leaked IntentReceiver com.mazenrashed.printooth.utilities.Bluetooth$3@4ee1a0b that was originally registered here. Are you missing a call to unregisterReceiver()?
or am i forget to initialized something ?
Basically, i wanted to use more than one printer. isit possible? and how do i determine which printer is paired to the Printooth. I couldn't find any documentation out there that are saving printer name, if any, can you provide one.
Thanks
Hi, Does any one has Printooth working in Android 10?
I made an app and use this great printer function, works perfect in Android 9 but some one tested in Android 10 and does not work.
Thanks for your advice or suggestions.
al.add( (new TextPrintable.Builder())
.setText(text)
.setCharacterCode(DefaultPrinter.Companion.getCHARCODE_THAI42())
.setNewLinesAfter(1)
.build());
Hi @mazenrashed ,
need to know how to print 2 different text alignment (right and left) on the same line.
E.g:
| Items's Name...............................Price |
| Pen A.............................................$ 5.21 |
where the "|" char is edge of paper, and "." is space char
my current code is like bellow:
printables.add(new TextPrintable.Builder()
.setText("Pen A")
.setAlignment(DefaultPrinter.Companion.getALIGNMENT_LEFT())
.build()
);
printables.add(new TextPrintable.Builder()
.setText("$ 5.21")
.setAlignment(DefaultPrinter.Companion.getALIGNMENT_RIGHT())
.setNewLinesAfter(1)
.build()
);
produces:
| .............................................Pen A$ 5.21 |
also when printing some Arabic text it print out black box
The thing is TextPrintable with alignment_left without setting newLinesAfter makes text to move end.
For example, I want to align two texts at the same line. One with left alignment the next one right alignment.
add(
TextPrintable.Builder()
.setText("${documentTitle}")
.setCharacterCode(DefaultPrinter.CHARCODE_PC866)
.setAlignment(DefaultPrinter.ALIGNMENT_LEFT)
.build()
)
add(
TextPrintable.Builder()
.setText("${documentNumber}")
.setCharacterCode(DefaultPrinter.CHARCODE_PC866)
.setAlignment(DefaultPrinter.ALIGNMENT_RIGHT)
.setLineSpacing(LINE_SPACING_1)
.setNewLinesAfter(1)
.build()
)
This make whole both text align to right.
I'm trying to print to more than one printer simultaneously, seve.
sometimes it works at other times
when i select device from scanning activity then in result i get this error
getBluetoothService() called with no BluetoothManagerCallback
i have search in depth your liberary file and i found that you have missed some code right here in bluetooth class
ConnectThread(BluetoothDevice device, boolean insecureConnection) {
Bluetooth.this.device = device;
try {
if (insecureConnection) {
Bluetooth.this.socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
} else {
Bluetooth.this.socket = device.createRfcommSocketToServiceRecord(uuid);
}
} catch (IOException e) {
if (deviceCallback != null) {
deviceCallback.onError(e.getMessage());
}
}
}
after this try
try {
if (insecureConnection) {
Bluetooth.this.socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
} else {
Bluetooth.this.socket = device.createRfcommSocketToServiceRecord(uuid);
}
} catch (IOException e) {
if exception occured you need to look for another connection which is also used commonly
that is
Method m = device.getClass().getMethod("createRfcommSocket", Integer.TYPE);
Bluetooth.this.socket = (BluetoothSocket) m.invoke(device, new Object[]{1});
Is this code will work for the thermal printres?
Hi there,
I've followed your readme steps but it doesnt work unfortunately.
...
startActivityForResult(Intent(this, ScanningActivity::class.java), ScanningActivity.SCANNING_FOR_PRINTER)
...
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER && resultCode == Activity.RESULT_OK) {
var printables = ArrayList<Printable>()
var printable = TextPrintable.Builder()
.setText("Hello World")
.build()
printables.add(printable)
Printooth.printer().print(printables)
}
}
I receive no errors only those debug messages and the printer is paired successfully
D/printer: com.mazenrashed.printooth.data.PairedPrinter@90312a
D/BluetoothAdapter: cancelDiscovery
D/BluetoothAdapter: cancelDiscovery = true
D/BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null
W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
The app is running on android 9
I have trouble integrating printooth to my project. I get this error "Failed to resolve: com.github.mazenrashed:Printooth:1.2.0" , any idea how to fix ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.