1

I want to print image / Receipt by connecting I to the thermal printer using Core Bluetooth Framework.

I have tried converting image to Data and then write it..I can successfully print image with size of 120x120 pixel, but unable to print image greater than 120 pixels

let  image = UIImage(named: "demo")
let data = image?.pngData()

guard let peripheral = connectedPeripheral, let characteristic = writableCharacteristic else {
            print("inside else")
            return
}
        
peripheral.writeValue(data, for: characteristic, type: .withoutResponse)

I have also tried using Printer pod

I have also tried it by converting image to bitmap and then to data, also tried to Encode it using base64 String.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
TasZ
  • 167
  • 11
  • What happens when the size is bigger? – cora Mar 08 '21 at 13:27
  • @cora I have used pods 'Printer' using ticketImage class i print my image..it only prints image less than 120 pixel..i tried 160px it prints by taking sometime and with 360 pixel image gets distorted that too it prints after some delay..other size images are not working – TasZ Mar 08 '21 at 15:57

1 Answers1

0

There are several of questions that you need to ask yourself.

  1. What is the MTU negotiated during the peripheral discovery?
  2. If the data you are trying to write to the peripheral is larger than the MTU, how does 'Printer' break it down into multiple packets?
  3. How does the peripheral know there are multiple packets incoming? (I had to send a special character to start the stream and another to end it. Every peripheral handles this differently).
  4. How does the peripheral reassemble multiple packets?
cora
  • 1,916
  • 1
  • 10
  • 18
  • can you please share code for how to send it using chunks/packets? – TasZ Mar 09 '21 at 12:08
  • can you please let me know why image prints garbage value..I am converting image into black and white first and then converting it into data and after that I am passing it into chunks – TasZ Mar 09 '21 at 13:19
  • It is possible that the printer does not know that you are passing chunks. It might just be printing the first chunk thinking that’s all there is. – cora Mar 09 '21 at 13:54