Giter Site home page Giter Site logo

printer's Introduction

ESC/POS Printer Driver for Swift

Description

Swift ticket printer framework for ESC/POS-compatible thermal printers

Requirements

  • iOS 12.0+
  • Swift 5.3+

Installation

CocoaPods

iOS 12 and newer

Printer is available on CocoaPods. Simply add the following line to your podfile:

# For latest release in cocoapods
pod 'Printer', :git => 'https://github.com/KevinGong2013/Printer.git', :branch => 'refactor'

Getting Started

Import

import Printer

Create ESC/POS Ticket

    let receipt = Receipt(.🖨️58(.ascii))
    <<~ .style(.initialize)
    <<< Image(cgImage)
    <<< "Testing"
    <<< "Testing"
    <<< KV("k", "v")
    <<~ .style(.clear)
    <<< Image(cgImage, grayThreshold: 28)
    <<< Dividing.`default`()
    <<~ .page(.printAndFeed(lines: 0))
    <<~ .style(.initialize)
    <<< QRCode(content: "https://www.apple.com")
    <<~ .style(.underlineMode(.enable2dot))
    <<~ .page(.printAndFeed(lines: 10))
    
    printer.write(Data(receipt.data))

Write Ticket to Hardware

// connect your pirnter&print ticket.
private let bluetoothPrinterManager = BluetoothPrinterManager()
private let dummyPrinter = DummyPrinter()

 if bluetoothPrinterManager.canPrint {
    bluetoothPrinterManager.write(ticket)
  }
dummyPrinter.write(ticket)

Receipt

[TODO]

Notes

  • Send data to your own Bluetooth Manager is possible

printer's People

Contributors

bo-rik avatar chibombo avatar gelagnolidze avatar kevingong2013 avatar nsurlsession0 avatar pylearndl avatar tomaslize avatar xioshock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

printer's Issues

Title size

Hi, great work the best printer helper so far.

Any way to change the size of the title font, already try small but no quite I was looking for.

Objective C samples?

I tried this on a ZJ-58 printer, it works fine.
How can I implement this in a Obj-C Project?

multiple item

how to print multiple item in one by one dynamically?
can I write (var ticket = Ticket()) for loop?

Remove extra line feed/return?

there is a new line for every text i print, like the example below
how can i fix this?

.plainText("Text A"),
.plainText("Text")

Text A

Text B

.plainText("Text A\n Text B"), this works but i want to use the block w/ text alignment

Text A
Text B

IMG_5866

Unknown class _TtC7Printer26PrinterTableViewController in Interface Builder file.

When i run the sample code of latest release 4.0.1 and proceed to bluetooth list it gives the following error in logs "Unknown class _TtC7Printer26PrinterTableViewController in Interface Builder file" whereas if I run the sample code of release 3.0.7 it works fine and displays the list of devices available.

Tested on Xcode 11.1

Found the Issue - In the latest release 4.0.1 the custom class name of bluetooth list view controller in MainStoryBoard should be 'BluetoothPrinterSelectTableViewController' instead of 'PrinterTableViewController'

Picture printing does not respond

The print of the picture did not respond, and I did not know why. But there are some bytes. output.Other functions are normal.

Please help me if you can. Thank you!!

How to print N number of text. right now printer is not printing more then 3-4 lines of text

var receipt = Receipt(
.text(.init(content: "DKSH SMOLLAN FIELD MARKETING MYANMAR LIMITED", predefined: .alignment(.center))),
.text(.init(content: "Singha Order Collection Myanmar", predefined: .alignment(.center))),
.kv(key: "UserdD: 202739", value: "Date: 2019-07-12"),
.kv(key: "User Name: mm01a1111", value: "Time: 11:26"),
.kv(key: "Please pick the order product name", value: "Please pick the order product name"),
.blank,
.text(.init(content: "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849501234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849501234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950"))
)

Text was truncated.

Problems printing German letters

Hi,

the printer doesn't print German letters like Ä,Ö or Ü instead it prints "ü0ë5" for example. Tried different code pages that the printer supports but not much has changed. Any idea how to resolve this?

The result print out is empty

Hi KevinGong,

i have try created new project and implemented this library.
when i searching the printer, the printer found and success connected.
i have issue when i try to print out, the result on the paper is empty.

detail my printer
my printer : Thermal receipt printer
model: PRJ CX-58B
Interface : USB+BT2.0+BT4.0
Brand : Panda

how to fix this issue ?

I can't print second time

Thankful for this library, it helps me a lot, but I can't print second time after printing first time. For print second time I restart my bluetooth at every time

Barcode

Can you help with barcode printing?

image printing error and QR not printing

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

Fatal error: printer manager must not be nil.

Hi Kevin, I used your library before, but now it throws an error, can you help me with this?

Fatal error: printer manager must not be nil.: file /code/Swift/Project/Pods/Printer/Printer/Source/Hardware/Bluetooth/BluetoothPrinterSelectTableViewController.swift, line 65

How to Print PDF file.

Hello,
I am Showing a PDF file in a WKWebView. I just wants to know how can i convert the content to ticket and print that PDF file? Please Help!!

Paper Size Height is Limited

Hello Guys Please help me on how to set the paper size to auto.. everything works well but when you print a receipt that has many details, let say 16 inches in height.. the printer only prints 10 inches of that then it will stop.. please help me guys :-(

QR code

Hi! thank you for sharing this. I can't find a way to print a QR code in my receipt. Do you know anything about this?

Request

Hi Kevin, I have a small problem here, this is my class, it has also the same name as yours: Printer. The purpose of my class is to print logs. It's a fancy replacement of default "print" function. Long story short: This is the first time, I am trying to add my class as a Pod on CocoaPods so that it's easily available for anyone who's using CocoaPods in their project. Now the thing is that I can't claim the same name as your as you have already taken the Printer for this repo. No problem, as I was not aware of the this already, I changed my spec name to "printer-logger" and changed the file name too [this is required]. All good well and I were able to add my class on CocoaPods. So now the time to test it so when I test I found these problems.

  1. I can't import "Printer" as it's there but I can't. I needed to import "printer_logger" [dash converted to underscore].
  2. As I can't import the Printer class, I can't use any functions of it. Everything becomes none of the use.
  3. I have linked this class URL at multiple places including my blog and maybe people will not like if I will completely rewrite everything. Class name, examples, Github readme, and other places.

In this case? What should I do? As I am really new to this, I am not sure which steps I can take further?

I am only thinking if no solution works may be you can change your pod name to something else to justify my class? Anything you do or advice will be much appreciated.

Line Spacing is too narrow.

Hey,

I had been looking for legit swift thermal printer library and yours is simply amazing.

It's faster and organized I just loved it. I really appreciated that you shared this.

I successfully imported to my project yesterday, however, I found something different with the previous one.

The space between two lines are really narrow, I tried not to bother you and figure it out myself.

Since I could make doubleHeight function alone, so I thought I could also do it this function as well.

However, I'm not sure how I can set default line spacing or send gap between lines?

Could you give me little tips, I would be very appreciated.

Also, I'm a noobie and I don't know about the policy or accustom on Github anyhow I missed it, please kindly guide me. Thanks millions.

Ticket is not included in the cocoapod

Great job creating this project. I was able to include the files just fine. Thank you for working on it.

Only when I try to use it with Cocoapods, after running pod install, the Ticket.swift and many other sources are not downloaded. See here

Not able to get the full Image Print by the thermal printer

Hi, i am using the MPT-III thermal printer and i have used your library into one of my projects to print the image

what i know so far is :
-Printer will print the image only if the image width is divisible by 8

  • Printer will print the image only the image is square like : 128 X 128, 256 X 256, 512 X 512 etc..

What i am doing :
Actually i have to print the pdf through thermal printer so what i am doing is converting the pdf into image and i have the image of with : 544 Height and 3434 width

Well i need the image vertically so i am rotating the image with 90 degree through that i am getting a new image of 3434 Height and 544 Width

So when i m trying to print the image using ticket the image is perfectly fine but after printing the half image or 1/4 of image the printer stops printing the image can anyone please help me Thanks a lot in advance.

Also one more thing when i m trying to print the same image with 264 Height and 1575 Width the full image is printing but it looks small

Anyone who finds the solution please let me know : Thank you!

Set different character code esc/pos command

Hi I would like to pass an ESC/POS command to the printer to set the encoding.

Specifically trying to pass the 'ESC t n' command where 'n' is a number defined in the character code table.

Based on this pod how can this be done?

Tried several things with no success.

Thank you in advance

Type 'Block' has no member 'dividing'

Hi I wanted to use your library but it doesn't work,
I took the code from the example and I get this error:
var receipt = Receipt(
.dividing, Type 'Block' has no member 'dividing'
.qr("Icey.Liao"),
.dividing )

TicketImage not visible

I'm not able to print a 128x128 full black image (or any other image).

TicketImage code:

        Block.defaultFeedPoints = 30
        
        var ticket = Ticket()
        ticket.feedLinesOnTail = 3
        ticket.feedLinesOnHead = 0

        ticket.add(block: .image(UIImage(named: "black")!, attributes: TicketImage.PredefinedAttribute.alignment(.center)))
        ticket.add(block: .title("TEST"))
        ticket.add(block: .text(.init(content: "TEST", predefined: .alignment(.left))))
        ...

        ... print

Should this depend on the printer device?
I'm using a GOOJPRT PT-210 thermal printer.

Everything else works great!

No text is printing

Running the sample application but it is just printing images and QR and the last line in the blocks. it skips all other lines but adds spaces instead of the text

Printing without extra Line

It is possible to print without Extra space between lines?

` var ticket = Ticket(
.title("Recibo de Pago"),
.dividing,
.text(.init(content: "Test", predefined: .alignment(.center))),
.text(.init(content: "", predefined: .alignment(.center))),
.dividing,
.text(.init(content: Date().description, predefined: .alignment(.center))),
.kv(k: "Cliente:", v: nombreCliente),
.kv(k: "# confirmacion:", v: numConfirmacion),
.text(.init(content: "Detalle", predefined: .alignment(.center))),
.kv(k: "Monto Pagado:", v: montoPagado),
.kv(k: "Monto Restante", v: montoRestante),
.dividing,
Block(Text(content: "Gracias por su Pago", predefined: .alignment(.center)))
)
ticket.feedLinesOnHead = 0
ticket.feedLinesOnTail = 0

    ReadyToPrint(ticket: ticket);
}`

TicketExample

Printer printing Random chinese text

For some reasons it's printing Weird text.
This is my code:

var ticket = Ticket(
            .title("App name"),
            .blank,
            .plainText("Customer name"),
            .plainText("1234567890"),
            .blank,
            .text(.init(content: Date().description, predefined: .alignment(.center))),
            .blank,
            .kv(k: "Merchant ID:", v: "iceu1390"),
            .kv(k: "Terminal ID:", v: "29383"),
            .blank,
            .kv(k: "Transaction ID:", v: "0x000321"),
            .plainText("PURCHASE"),
            .blank,
            .kv(k: "Sub Total", v: "USD$ 25.09"),
            .kv(k: "Tip", v: "3.78"),
            .dividing,
            .kv(k: "Total", v: "USD$ 28.87"),
            .blank(3),
            Block(Text(content: "Thanks for supporting", predefined: .alignment(.center))),
            .blank,
            
            .text(.init(content: "THANK YOU", predefined: .bold, .alignment(.center)))
        )
        
        ticket.feedLinesOnHead = 0
        ticket.feedLinesOnTail = 0
        
        if bluetoothPrinterManager.canPrint {
            bluetoothPrinterManager.print(ticket)
        } else {
            dummyPrinter.print(ticket)
        }

print

Latin 2 support

Hi Kevin,

How to edit source for support Latin 2 characters?

Appstore rejection

Hi KevinGong,

We have a project of food ordering & delivery APP which is live on AppStore right now.As per our client requirement users should be able to print receipt of order from app. So we have used this library to print receipt and it is working fine. But when we updating this functionality with new build on AppStore they are demanding MFi Product Plan ID (PPID).Can you send us confirmation for that.

Papar cut command

Hello Kevin, I have successfully implemented your code in my project and it really works like a charm, but I have searched in your code there is no command to cut paper partially or cut full and print any image.
I have tried with the reference document attached with the example but i had no luck.
Can you please suggest me how to implement paper partially cut command and print image.

Thank you again for this wonderful project.

[CoreBluetooth] XPC connection invalid

When presenting the PrinterTableViewController, I am getting an error:
[CoreBluetooth] XPC connection invalid
The code I am using is quite simple:
let pm = PrinterManager()
if !pm.canPrint {
let vc = PrinterTableViewController()
vc.sectionTitle = "Choose Printer"
vc.printerManager = pm
self.navigationController?.pushViewController(vc, animated: true)
}
Any suggestions for me to get this working? I can provide more information if needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.