Giter Site home page Giter Site logo

hellotime / printer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kevingong2013/printer

0.0 1.0 0.0 163 KB

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

License: Apache License 2.0

Ruby 15.94% Objective-C 0.84% Swift 83.22%

printer's Introduction

ESC/POS Printer Driver for Swift

Description

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

Features

  • Supports connect bluetooth printer.
  • Create printable ticket easily.

Requirements

  • iOS 9.0+
  • Swift 5.0

Installation

CocoaPods

iOS 9 and newer

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

# For latest release in cocoapods
pod 'Printer'

Carthage

github "KevinGong2013/Printer"

Swift Package Manager

File -> Add Package -> Enter Package URL

https://github.com/KevinGong2013/Printer

Getting Started

Import

import Printer

Create ESC/POS Ticket

var ticket = Ticket(
            .title("Restaurant"),
            .blank,
            .plainText("Palo Alto Californlia 94301"),
            .plainText("378-0987893742"),
            .blank,
            .image(image, attributes: .alignment(.center)),
            .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))),
            .blank(3),
            .qr("https://www.yuxiaor.com")
        )
        
        ticket.feedLinesOnHead = 2
        ticket.feedLinesOnTail = 3

Write Ticket to Hardware

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

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

Ticket && Blocks

[TODO]

Notes

  • Send data to your own Bluetooth Manager is possible

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.