RasterizedReceiptPrinting 0.1.5

RasterizedReceiptPrinting 0.1.5

Maintained by Tien Pham.




RasterizedReceiptPrinting

CI Status Version License Platform

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

License

RasterizedReceiptPrinting is available under the MIT license. See the LICENSE file for more info.