Open lehuydev2203 opened 4 years ago
Same here
@tr3v3r @lehuyroxyproduction this library is "bridged" from a prebuild library libPrinterSDK.a
provided along with the thermal printer. So this error could happen when that library is not build with bitcode is enabled. You guys could try to disable that property on your build:
Build Setting -> Build Options -> Enable Bitcode: No
@HeligPfleigh it helped with the build but now the printer doesn't want to print text if I try to off some style.
const BOLD_ON = \x1b\x45\x01;
const BOLD_OFF = \x1b\x45\x00;
`
${BOLD_ON} Hello world! ${BOLD_OFF}
Test printer text
`
Previously with Enable Bitcod: YES I got :
Hello world! Test printer text
But now printer stop printing every time I try to OFF any style. So in this case I'm getting:
Hello world!
"Test printer text" is missed!
I have been using esc-pos-encoder to do everything. https://www.npmjs.com/package/esc-pos-encoder That works with Bitcode set to No.
I have been using esc-pos-encoder to do everything. https://www.npmjs.com/package/esc-pos-encoder That works with Bitcode set to No.
Hey, how are you decoding the encoded Uint8Array
array generated from esc-pos-encoder
? I've tried https://www.npmjs.com/package/text-encoding, but it seems to create a huge space between lines. Thanks.
@KamauIan I forked react-native-thermal-receipt-printer to add a new printRaw method. Then I am using the following to convert to base64.
//buffer-helper.js
import { Buffer } from 'buffer'
export default class BufferHelper {
buffers: Buffer[]
size: number
constructor() {
this.buffers = []
this.size = 0
}
get length() {
return this.size
}
concat = (buffer: Buffer): BufferHelper => {
this.buffers.push(buffer)
this.size += buffer.length
return this
}
empty = (): BufferHelper => {
this.buffers = []
this.size = 0
return this
}
toBuffer = (): Buffer => Buffer.concat(this.buffers, this.size)
toString = (encoding: BufferEncoding): string => this.toBuffer().toString(encoding)
load = (stream: any, callback: any) => {
stream.on('data', (trunk: Buffer) => {
this.concat(trunk)
})
stream.on('end', () => {
callback(null, this.toBuffer())
})
stream.once('error', callback)
}
}
const bytes = new BufferHelper()
bytes.concat(new Buffer(cmds))
const buffer = bytes.toBuffer()
// console.log(buffer.toString())
NetPrinter.printRaw(buffer.toString('base64'))
@harshmaur What about iOS? This works only for android ;(
@tr3v3r oh okay. I didn't try it on iOS. Whats the problem do you get in iOS?
@tr3v3r oh okay. I didn't try it on iOS. Whats the problem do you get in iOS?
printRaw data prints on iOS simple text ( not binary data ). But it seems printer library SDK provides method printHex. Looking into it now
Btw, I created a printRaw method in the library myself. I think I forgot to create a PR from my forked repo to this. I'll make one.
@harshmaur Yes, I've already tested your forked repo, but as I understood you just made printRaw method public, but under the hood, it behaves as I described above on iOS. And it crashes on iOS for now because it requires 3 arguments instead of 2.
My archive still fails with the same error even with Bitcode Enabled = No, in project > build settings and target > build settings. Any idea?
Update - I had to set No to Bitcode Enabled in both project and target and the build worked.
@KamauIan I forked react-native-thermal-receipt-printer to add a new printRaw method. Then I am using the following to convert to base64.
//buffer-helper.js import { Buffer } from 'buffer' export default class BufferHelper { buffers: Buffer[] size: number constructor() { this.buffers = [] this.size = 0 } get length() { return this.size } concat = (buffer: Buffer): BufferHelper => { this.buffers.push(buffer) this.size += buffer.length return this } empty = (): BufferHelper => { this.buffers = [] this.size = 0 return this } toBuffer = (): Buffer => Buffer.concat(this.buffers, this.size) toString = (encoding: BufferEncoding): string => this.toBuffer().toString(encoding) load = (stream: any, callback: any) => { stream.on('data', (trunk: Buffer) => { this.concat(trunk) }) stream.on('end', () => { callback(null, this.toBuffer()) }) stream.once('error', callback) } }
const bytes = new BufferHelper() bytes.concat(new Buffer(cmds)) const buffer = bytes.toBuffer() // console.log(buffer.toString()) NetPrinter.printRaw(buffer.toString('base64'))
Hi @harshmaur nice work, I'm trying to understand your last snippet, is that for printing what? images?
Also, what does cmds stands for here: bytes.concat(new Buffer(cmds))
And finally If I use your fork instead along with esc-pos-encoder
I have to pass the encoded result straight to your printerRaw
method?
@ghacosta cmds
is nothing but the raw string of commands. In your case it will be the encoded result from esc-pos-encoder
@ghacosta @harshmaur BTW I've forked repo too and added printRaw
method for iOS as well
https://github.com/tr3v3r/react-native-thermal-receipt-printer
with full compatibility with esc-pos-encoder
const encoder = new EscPosEncoder();
encoder
.codepage('cp858')
.align('center')
.line('hello')
NetPrinter.printRawData(encoder.encode())
@HeligPfleigh are you acepting PRs? Maybe you guys @harshmaur @tr3v3r can submit your improvements. I'm able to help you testing if you like.
I prefer to have this in the main library instead of forking your (GREAT) work!
@ghacosta @harshmaur @tr3v3r yes, I always welcome to PR :+1: Feel free to open and assign it to me, thank you
@ghacosta @harshmaur @HeligPfleigh Sorry for that, but because of a lot of limitations of this library I had to export the native Epson ePOS SDK for Android and iOS to React Native.
It currently supports TCP
, USB
, and Bluetooth
connections. Provides searching
, `printing' methods.
SDK also provides a ton of other handy methods like printing images - but still, work in progress.
You can try it on your own react-native-esc-pos-printer
I'd really grateful for any contribution ;)
@tr3v3r does that library work for all thermal printers?
Which one @francesco-clementi-92 ?
When i build release , it be error like that
please help me , thank you .