Swiftpack.co - KevinGong2013/Printer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by KevinGong2013.
KevinGong2013/Printer 4.0.1
Swift ticket printer framework for ESC/POS-compatible thermal printers.
⭐️ 139
🕓 2 years ago
iOS
.package(url: "https://github.com/KevinGong2013/Printer.git", from: "4.0.1")

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

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics