RasterizedReceiptPrinting
Printing Unicode with Command mode to Receipt printers are not reliable. The best solution so far is to printing to a UIImage and then send the whole image over to printer. With this approach, developer can control totally the Unicode printing work and it''s easier to manage the layout. However, Mono-Font must be used to make alignment more precise.
Usage
Firstly, we must create a NSAttributedString
.
-
Implement Swift:
let printTemplate = NSMutableAttributedString(string: "")
Then, we can append new attributed string for this template like this.
-
Implement Swift:
printTemplate.append("Hello World!!!\n") printTemplate.appendCenter("This is a center body.\n") printTemplate.appendBold("End World!!!\n")
Finally, create image from custom string with page width setting.
-
Implement Swift:
let image = printTemplate.rasterize(width: 576)
Congratulations! You're done.
Installation
RasterizedReceiptPrinting is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RasterizedReceiptPrinting'
Before using module
Swift
Add the following line in your Swift file:
import RasterizedReceiptPrinting
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- Swift 4.0
- iOS 9.0 or later
Author
- Chinh Nguyen, [email protected]
- Tien Pham, [email protected]
License
RasterizedReceiptPrinting is available under the MIT license. See the LICENSE file for more info.