Open hm-harshit opened 5 years ago
Look comments in #8
Any updates? Comments from that thread didnt work for me. I am using a TM-P80 Epson printer. the manual has the following code pages Page 32 (PC720: Arabic) Page 37 (PC864: Arabic) Page 50 (WPC1256: Arabic)
used all it prints gibberish. Any help would be appreciated.
Hello @MurtazaEliyas any updates? have you made it work? printing arabic? I also tried the thread @mainginski sent but it also didn't work
@jiloysss I tried a lot with different combinations of codepages and encodings. I also had to test on multiple brands of printers: Xprinter, Epson, TSC and Bixolon.. all gave same results.
I used encoding:'Arabic', codepage: 22 in all my tests. It printed Arabic characters but in reverse so I reversed the strings to be printed before sending in printText method like shown below
let string = ' اهلا و مرحبا مسرة\n\r';
string = string.split('').reverse().join('');
The result was not very good
Finally we decided to make a bridge to native layer. And have the printers sdk (.jar file) help us in printing Arabic text. We read a little on how this library prints columns as that was something we wanted. Turns out its just looping and snipping strings to required column sizes then printing them line by line.
We have put the printer on pause for now. Will share more once its all implemented.
Hope this helps
Okay @pssolutions thank you very much.
using react-native-view-shot and react-native-fs help me to solve the issue. the approach is to take screenshot of the view and then read it as base64 and then send it to printer. the good thing is that you can use your custom font and custom design to print every thing that you want. the issue that I face was that image not scale the whole screen and I solve it in this comment image scale fixed
hey ! Can I ask u question about this ?
@islamabujamea yeah why not
@EhsanSarshar Hello brother... I have issue regrading Arabic text print.can you share your code to me please.how to get screenshot and read it as base64 and how you send to printer.im waiting your replay.
@FazilMuhammed here are key parts
import {
BluetoothEscposPrinter,
BluetoothManager,
BluetoothTscPrinter,
// @ts-ignore
} from 'react-native-bluetooth-escpos-printer'
import fs from 'react-native-fs'
import ViewShot from 'react-native-view-shot'
const captureRef = useRef()
const printIt = async () => {
if (captureRef.current) {
const imageUri = await captureRef.current.capture({
result: 'tmpfile',
width: 1000,
})
const base64 = await fs.readFile(imageUri, 'base64')
await BluetoothEscposPrinter.printerInit()
await BluetoothEscposPrinter.printerAlign(
BluetoothEscposPrinter.ALIGN.CENTER,
)
await BluetoothEscposPrinter.printPic(base64, {width: 630})
}
}
return (
<View style={styles.all}>
<ViewShot ref={captureRef} style={styles.body}>
<View style={styles.header}>
<Image
resizeMode="contain"
source={require('../someImage.png')}
style={styles.logo}
/>
<View>
<Text style={styles.title}>یک متن جعلی</Text>
<Text style={styles.address}>
هرات افغانستان
</Text>
</View>
<Text style={styles.footerText}>تشکر از خریداری تان</Text>
</View>
</ViewShot>
<TouchableOpacity onPress={printIt} style={styles.button}>
<Text style={styles.printText}>print</Text>
</TouchableOpacity>
</View>
)
@EhsanSarshar Thanks for your reply. one more also I have the doubt. how will you connect the printer to your Mobile can share the code to me please. I working IOS I cannot print the datas couple months get stuck on this issue please help me.
@FazilMuhammed here are key parts
import { BluetoothEscposPrinter, BluetoothManager, BluetoothTscPrinter, // @ts-ignore } from 'react-native-bluetooth-escpos-printer' import fs from 'react-native-fs' import ViewShot from 'react-native-view-shot' const captureRef = useRef() const printIt = async () => { if (captureRef.current) { const imageUri = await captureRef.current.capture({ result: 'tmpfile', width: 1000, }) const base64 = await fs.readFile(imageUri, 'base64') await BluetoothEscposPrinter.printerInit() await BluetoothEscposPrinter.printerAlign( BluetoothEscposPrinter.ALIGN.CENTER, ) await BluetoothEscposPrinter.printPic(base64, {width: 630}) } } return ( <View style={styles.all}> <ViewShot ref={captureRef} style={styles.body}> <View style={styles.header}> <Image resizeMode="contain" source={require('../someImage.png')} style={styles.logo} /> <View> <Text style={styles.title}>یک متن جعلی</Text> <Text style={styles.address}> هرات افغانستان </Text> </View> <Text style={styles.footerText}>تشکر از خریداری تان</Text> </View> </ViewShot> <TouchableOpacity onPress={printIt} style={styles.button}> <Text style={styles.printText}>print</Text> </TouchableOpacity> </View> )
can you help me it is not working i got blank paper
@pssolutions did you manga to make work print in arabic
@jiloysss I tried a lot with different combinations of codepages and encodings. I also had to test on multiple brands of printers: Xprinter, Epson, TSC and Bixolon.. all gave same results. I used encoding:'Arabic', codepage: 22 in all my tests. It printed Arabic characters but in reverse so I reversed the strings to be printed before sending in printText method like shown below
let string = ' اهلا و مرحبا مسرة\n\r';
string = string.split('').reverse().join('');
The result was not very good
Finally we decided to make a bridge to native layer. And have the printers sdk (.jar file) help us in printing Arabic text. We read a little on how this library prints columns as that was something we wanted. Turns out its just looping and snipping strings to required column sizes then printing them line by line.
We have put the printer on pause for now. Will share more once its all implemented.
Hope this helps
did you manga to make work print in arabic
@feras-merwas No we did not continue with the solution. The printer task never resumed. However I think things might have changed now with newer libraries. Will post here if I find anything
@pssolutions thank you
@FazilMuhammed here are key parts
import { BluetoothEscposPrinter, BluetoothManager, BluetoothTscPrinter, // @ts-ignore } from 'react-native-bluetooth-escpos-printer' import fs from 'react-native-fs' import ViewShot from 'react-native-view-shot' const captureRef = useRef() const printIt = async () => { if (captureRef.current) { const imageUri = await captureRef.current.capture({ result: 'tmpfile', width: 1000, }) const base64 = await fs.readFile(imageUri, 'base64') await BluetoothEscposPrinter.printerInit() await BluetoothEscposPrinter.printerAlign( BluetoothEscposPrinter.ALIGN.CENTER, ) await BluetoothEscposPrinter.printPic(base64, {width: 630}) } } return ( <View style={styles.all}> <ViewShot ref={captureRef} style={styles.body}> <View style={styles.header}> <Image resizeMode="contain" source={require('../someImage.png')} style={styles.logo} /> <View> <Text style={styles.title}>یک متن جعلی</Text> <Text style={styles.address}> هرات افغانستان </Text> </View> <Text style={styles.footerText}>تشکر از خریداری تان</Text> </View> </ViewShot> <TouchableOpacity onPress={printIt} style={styles.button}> <Text style={styles.printText}>print</Text> </TouchableOpacity> </View> )
can you help me it is not working i got blank paper
Yeah sure! send me your source code.
@TheEhsanSarshar hello this is my code when print i got weird character
import { BluetoothManager, BluetoothEscposPrinter, } from 'react-native-bluetooth-escpos-printer';
version '0.0.5'
printIt = async () => {
const imageUri = await this.refs.viewShot2.capture({
result: 'tmpfile',
width: 1000,
});
const base64 = await FileSystem.readFile(imageUri, {
encoding: 'base64',
});
await BluetoothEscposPrinter.printerInit();
await BluetoothEscposPrinter.printerAlign(
BluetoothEscposPrinter.ALIGN.CENTER,
);
console.log(`base64`, base64);
try {
await BluetoothEscposPrinter.printPic(base64, {
width: 100,
left: 0,
});
} catch (e) {
console.log(e || 'ERROR');
console.log(e);
}
};
return (
<View style={styles.Maincontainer}>
<ViewShot ref="viewShot2" style={styles.body}>
<Image
resizeMode="contain"
source={require('../../../../assists/img/cloud.jpg')}
style={{width: 100, height: 100}}
/>
</ViewShot>
<View
style={{
width: '100%',
padding: 10,
justifyContent: 'center',
alignItems: 'center',
}}>
<TouchableOpacity onPress={this.printIt} style={styles.button}>
<Text style={styles.printText}>print</Text>
</TouchableOpacity>
</View>
</View>
);
@FazilMuhammed here are key parts
import { BluetoothEscposPrinter, BluetoothManager, BluetoothTscPrinter, // @ts-ignore } from 'react-native-bluetooth-escpos-printer' import fs from 'react-native-fs' import ViewShot from 'react-native-view-shot' const captureRef = useRef() const printIt = async () => { if (captureRef.current) { const imageUri = await captureRef.current.capture({ result: 'tmpfile', width: 1000, }) const base64 = await fs.readFile(imageUri, 'base64') await BluetoothEscposPrinter.printerInit() await BluetoothEscposPrinter.printerAlign( BluetoothEscposPrinter.ALIGN.CENTER, ) await BluetoothEscposPrinter.printPic(base64, {width: 630}) } } return ( <View style={styles.all}> <ViewShot ref={captureRef} style={styles.body}> <View style={styles.header}> <Image resizeMode="contain" source={require('../someImage.png')} style={styles.logo} /> <View> <Text style={styles.title}>یک متن جعلی</Text> <Text style={styles.address}> هرات افغانستان </Text> </View> <Text style={styles.footerText}>تشکر از خریداری تان</Text> </View> </ViewShot> <TouchableOpacity onPress={printIt} style={styles.button}> <Text style={styles.printText}>print</Text> </TouchableOpacity> </View> )
I am getting black print in place of text or image. Please Help.
@tanishabedi @feras-merwas share yourlogcat
logs while printing.
it's sometimes because of device Ram issues
I tried to print Arabic but it doesn't work
I tried the function
await BluetoothEscposPrinter.printText("لا يوجد مجاني");
but it doesn't work
Is there is an option to print pdf files?