Prints to an Epson ESCPOS-Compatible Receipt Printer.
Resources:
Add ESCPOSKit to your project:
- Either, add it via Xcode.
- Go to your .xcodeproj file, select your project, and choose the "Package Dependencies" Tab
- Click on the "+", and enter "https://github.com/Jacobingalls/ESCPOSKit.git" into the search
- Pick the appropriate version (right now only main), select the ESCPOS target, and add it to your targets.
- Or, add it via the Swift Package Manifest (Package.swift)
- Add the package to your list of packages.
.package(url: "https://github.com/Jacobingalls/ESCPOSKit.git", .branch("main")) - And, add the package as a dependency of at least one of your targets.
- Add the package to your list of packages.
Then you may use it in your code.
import Foundation
import ESCPOS
letcommands:[ESCPOSCommand]=[.justification(.center),.characterSize(vertical:.double, horizontal:.double),.ascii("Hello, World!\n\n"),.justification(.left),.characterSize(vertical:.normal, horizontal:.normal),.ascii("Welcome to the exciting new world...\nprinting reciepts.\n"),.printAndFeed(lines:5),
// Cutting is not yet implemented in Commands...
.raw(.init([0x1D,0x56,0])),]letdata= commands.map(\.dataValue).reduce(into:Data(),{ $0.append($1)})
// My Epson TM-T20III Receipt Printer over USB
try!escposPrint(vendorId:0x04B8, productId:0x0202, data: data)