HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
155 stars 102 forks source link

In Android all predefined tags works but in iOS they are not working #21

Open GabrielMobileQD opened 3 years ago

GabrielMobileQD commented 3 years ago

When i run the following piece of code: await Printer.printText("<C>#3</C>\n<C>SUBWAY</C>\n<L>Nome:Joao Felipe Fonseca Nascimento</L>\n<L>Celular: +55 79 9 9685-9817</L>"); In Android works correctly as you can see in the image below, the formatting is totally correct: photo5066857470273628332 But, when i run in IOS it does not works correctly as you can see in the image below: photo5066857470273628331 So what do i need to do to solve this problem?

Thanks, Your lib is helping me a lot! Please solve my problem rsrs. I gave a star to you :).

lehuydev2203 commented 3 years ago

i think we just write function get length of content left and content right and subtract for total length 1 row is 42 char. and we have content 1 line = ${contentLeft}${space}${contentRight} space is result when we subtract length content left and content right .

GabrielMobileQD commented 3 years ago

@lehuyroxyproduction Thanks for your answer! But i didn't understand how your answer can solve my problem. Can you explain to me in a better way?

lehuydev2203 commented 3 years ago

This is my example

let SPACE_DEFAULT = 42

const ContentBill= (left?:String,right?:String)=>{ let contentLeft = left let contentRight = $${parseFloat(right).toFixed(2)} let leftLen = contentLeft.length let rightLen = contentRight.length let spaceLen = SPACE_DEFAULT - leftLen - rightLen let space='' for(let i = 0; i <spaceLen; i++ ){ space = space + ' ' } return ${contentLeft}${space}${contentRight} }

try { await NetPrinter.printBill(${ContentBill( 'Service' , '45' )}) }catch (err) { console.warn(err); }

hasithaWalpola commented 3 years ago

@GabrielMobileQD is this printText works for you? await Printer.printText("#3\nSUBWAY\nNome:Joao Felipe Fonseca Nascimento\nCelular: +55 79 9 9685-9817");

I tried it in my app the text doesn't print, it only a plan paper

GabrielMobileQD commented 3 years ago

Thanks @lehuyroxyproduction for writing the function for me, i'm gonna use it in my project to see if it works correctly! Yes @hasithaWalpola , for me it works! It's only happening the issue that I described above! Please say more details about your problem, i'll help in what i can asap! :)

hasithaWalpola commented 3 years ago

Thanks @GabrielMobileQD yeah it works for me, the issue is with my printer encoding type. Is there way to add margins and align the text?

GabrielMobileQD commented 3 years ago

You're welcome! You can align the text using the tags described in this lib doc, as you can see in the image below: Captura de Tela 2020-09-28 às 14 17 15

And i discovered by myself looking the lib code that you can align the text to the left using the tag {text you want} and to the right using the tag {text you want}. But i found that in iOS the Left and Right alignment tags are not working, that's why i opened this issue, they work just in Android.

mjm918 commented 3 years ago

Any update on this? I am facing the same issue

LukhiKartik commented 3 years ago

In my case, All other pre-defined tags except "C" are not working in iOS.

vatsal-gadhiya-searce commented 3 years ago

@HeligPfleigh In my case, except "C" tag all other predefined tags are not working in IOS. Can you suggest any workaround for font size please.

mjm918 commented 3 years ago

@vatsal-gadhiya-searce @LukhiKartik this is why it's not working. because they dont have such feature 😂 in they code for iOS they replace all the tags before insertion

https://github.com/HeligPfleigh/react-native-thermal-receipt-printer/blob/92adee45d79bfd97b491e9122bbee238c58f0304/dist/index.js#L39

vatsal-gadhiya-searce commented 3 years ago

@mjm918 I know their code :). But asking for any workaround to use different font-sizes and bold tags?

DamDucDuyIT commented 2 years ago

Does anyone have an idea for applying font size or left or right alignment for IOS? I am facing this issue too

lehuydev2203 commented 2 years ago

Does anyone have an idea for applying font size or left or right alignment for IOS? I am facing this issue too

Currently left and right I use the way is to count characters to format left and right. With a total of 1 line is 42 characters. then calculate the number of characters of the content minus the sum of 1 line characters and the remaining line number of characters insert the number of spaces