KevinGong2013 / Printer

Swift ticket printer framework for ESC/POS-compatible thermal printers.
Apache License 2.0
147 stars 73 forks source link

image printing error and QR not printing #15

Open ajay-pal-singh opened 5 years ago

ajay-pal-singh commented 5 years ago

guard let image = UIImage(named: "demo") else { return }

        var receipt = Receipt(
            .dividing,
            .qr("Icey.Liao"),
            .dividing,
            .image(image, attributes: [ImageBlock.PredefinedAttribute.alignment(.center)])
            //  Updated by Pradeep Sakharelia on 15/05/19
        )

        receipt.feedLinesOnTail = 2
        receipt.feedPointsPerLine = 60

        pm.print(receipt)

imgpsh_fullsize_anim

I am using above code to print image and Qr code but it shows error while printing, As Shown in image

pylearndl commented 5 years ago

Upload your demo image here. Is it jpg image you want to print? What is image size? Height x width of image ?

ajay-pal-singh commented 5 years ago

It is the same image that is in example of project with name demo.png

pylearndl commented 5 years ago

try code let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 1 let imgblock = ImageBlock(img, attributes: [ImageBlock.PredefinedAttribute.alignment(.center)]) receipt.add(block: imgblock) for datas in receipt.datas { let sendtest = self.client.send(data: datas as NSData) print("send data: \(sendtest)") } let me know what does it do

abu4tw commented 5 years ago

Image is work to me , but .qr only print string not QRcode, any one know how to make image printing alignment in center or print rectangle image

pylearndl commented 5 years ago

Try converting qr to image, then print

abu4tw commented 5 years ago

Try converting qr to image, then print

thanks. i will try..

ajay-pal-singh commented 5 years ago

let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 1 let imgblock = ImageBlock(img, attributes: [ImageBlock.PredefinedAttribute.alignment(.center)]) receipt.add(block: imgblock) for datas in receipt.datas { let sendtest = self.client.send(data: datas as NSData) print("send data: (sendtest)") }

It shows errors on these lines >

  1. receipt.add(block: imgblock) >>>> Cannot convert value of type 'ImageBlock' to expected argument type 'Block'
  2. for datas in receipt.data >>>> Type '(String.Encoding) -> [Data]' does not conform to protocol 'Sequence'
pylearndl commented 5 years ago

let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 1 let imgblock = ImageBlock(img, attributes: [ImageBlock.PredefinedAttribute.alignment(.center)]) receipt.add(block: imgblock) for datas in receipt.datas { let sendtest = self.client.send(data: datas as NSData) print("send data: (sendtest)") }

It shows errors on these lines >

  1. receipt.add(block: imgblock) >>>> Cannot convert value of type 'ImageBlock' to expected argument type 'Block'
  2. for datas in receipt.data >>>> Type '(String.Encoding) -> [Data]' does not conform to protocol 'Sequence'

try let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 2 receipt.add(block: Block.image(img, attributes [ImageBlock.PredefinedAttribute.alignment(.center)])) pm.print(receipt)

ajay-pal-singh commented 5 years ago

let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 1 let imgblock = ImageBlock(img, attributes: [ImageBlock.PredefinedAttribute.alignment(.center)]) receipt.add(block: imgblock) for datas in receipt.datas { let sendtest = self.client.send(data: datas as NSData) print("send data: (sendtest)") }

It shows errors on these lines >

  1. receipt.add(block: imgblock) >>>> Cannot convert value of type 'ImageBlock' to expected argument type 'Block'
  2. for datas in receipt.data >>>> Type '(String.Encoding) -> [Data]' does not conform to protocol 'Sequence'

try let img = UIImage(named: "demo")! var receipt = Receipt() receipt.feedLinesOnTail = 2 receipt.add(block: Block.image(img, attributes [ImageBlock.PredefinedAttribute.alignment(.center)])) pm.print(receipt)

Unfortunately same result, it just print 20% of image and then blank imgpsh_fullsize_anim (1)

Mahipal-codzgarage commented 5 years ago

@DhanjuAjay can you solved printing image issue?

ajay-pal-singh commented 5 years ago

@DhanjuAjay can you solved printing image issue?

Still not solved, even the example app is just printing title, then stop working.

pylearndl commented 5 years ago

@DhanjuAjay which thermal printer are you using? Have you tried another thermal receipt printer. It works on ESC/POS printers

Try 80mm thermal receipt printer from eBay will do the job

ajay-pal-singh commented 4 years ago

@DhanjuAjay which thermal printer are you using? Have you tried another thermal receipt printer. It works on ESC/POS printers

Try 80mm thermal receipt printer from eBay will do the job

I am using this printer:

https://www.amazon.com.au/NYEAR58-10mm-Personal-Wireless-Bluetooth-Compatible/dp/B07C8RDLZZ/ref=asc_df_B07C8RDLZZ/?tag=googleshopdsk-22&linkCode=df0&hvadid=341773403893&hvpos=1o1&hvnetw=g&hvrand=9311021397934973382&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9071510&hvtargid=pla-625816585876&psc=1

Not working for me

pylearndl commented 4 years ago

https://www.ebay.co.uk/c/1874761593 2017 WiFi POS Wireless Thermal Receipt Printer 80mm Auto ...

Successfully tested and working on these printers

ajay-pal-singh commented 4 years ago

Thanks for information, is there any way to Print from my printer ?

pylearndl commented 4 years ago

I think your printer is for label printing. I haven't tested my code on label printer.

I'm sure image will print, if you try print on 80mm receipt printer, is mainly used in epos receipt printing.

ajay-pal-singh commented 4 years ago

I think your printer is for label printing. I haven't tested my code on label printer.

I'm sure image will print, if you try print on 80mm receipt printer, is mainly used in epos receipt printing.

I have printer this print from android app, and printer works perfectly with an android library, but not with iOS library 😔 image

ajay-pal-singh commented 4 years ago

Hello , I have tested the latest example, now alignment is not working, initially example was working fine for text only IMG_0004

ntnhon commented 4 years ago

I am encountering the same issue, it just prints blank spaces. It even crashes sometimes. Is there a specific dimension for the images?

pylearndl commented 4 years ago

Print only square logo image. Try one of 32x32 px, 64x64, 128x128, 256x256. If your image is not any of these size than resize programmatically before give it to printer's receipt object.

ntnhon commented 4 years ago

@pylearndl I download your fork and run the sample project, the image is 40x40 so I resized it to 32x32, still it doesn't work. It will just print blank spaces. Did you test your fork on a real device?

pylearndl commented 4 years ago

Send me screenshot and error, what printer you using? My all deployed ios apps are working on wifi 80mm thermal printer just fine. Kevins' code wasn't working initially when I tried to integrate. I made my code to make it work and fork in his git to let others to use it.

ntnhon commented 4 years ago

@pylearndl thanks for the quick reply. Here is my printer specs

No error is logged to the console. The printer slightly prints a blank line. That's all my observation.

pylearndl commented 4 years ago

What printer you using? Send me image

pylearndl commented 4 years ago

I can see you trying to print on 58mm printer. Unfortunately I m not sure about it. I have tested and it's working absolutely fine on 80mm thermal receipt printers.

pylearndl commented 4 years ago

https://www.ebay.co.uk/c/1874761593 2017 WiFi POS Wireless Thermal Receipt Printer 80mm Auto ...

pylearndl commented 4 years ago

I sent you this link to see the printer ios code works. I haven't tested on any other thermal printers

ntnhon commented 4 years ago

@pylearndl it might be the problem of printer model. As I'm making a receipt printing app for a small business, a 80mm printer is way too big. I will wait for upcoming updates, for now I'm happy printing the logo as a large text. Thank you for your time 👍

pylearndl commented 4 years ago

Kevin has updated his code on GitHub with new version. You should try and see if it works for your 58mm printer. Just give it a go

chonnawee4 commented 4 years ago

I'm also can't print image on 58mm printer

KevinGong2013 commented 1 year ago

Printer has been rewrite.

select Mode to double width& double height

let receipt = Receipt(.🖨️58(.ascii))
<<~ .style(.initialize)
<<< Image(cgImage, mode: .doubleWH)
<<~ .page(.printAndFeed(lines: 1))

Image(cgImage, mode: .doubleWH) is key code.

kruyvanna commented 1 year ago

@pylearndl how to print non-square image?