用于 Swift 的 ESC/POS 打印机驱动程序

描述

用于 ESC/POS 兼容热敏打印机的 Swift 票据打印框架

要求

安装

CocoaPods

iOS 12 及更高版本

Printer 可在 CocoaPods 上获取。只需将以下行添加到您的 podfile

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

开始使用

导入

import Printer

创建 ESC/POS 票据

    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))

将票据写入硬件

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

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

收据

[待办]

注意