我正在关注用于集成的 git 演示示例:git:https ://github.com/star-micronics/StarPRNT-SDK-iOS-Swift 我已经成功安装了 sdk,并且能够在 EnglishReceiptsImpl 类中打印示例。
现在,我正在尝试打印我在 api 响应中得到的内容。
我担心:
- 有没有直接的方法来转换/传递 pdf url 来打印内容?
- 如何在“命令”中传递数据(Data/NSData)进行打印。
我正在使用/为TSP650II打印机型号工作。
我安装的豆荚是:
// Swift SDK 的 Pod
pod 'StarIO', '2.8.2'
pod 'StarIO_Extension', '1.15.0'
这是我的代码:
在类 SearchPortViewController
func openStarPrinter() {
var commands: Data
let localizeReceipts: ILocalizeReceipts = LocalizeReceipts.createLocalizeReceipts(AppDelegate.getSelectedLanguage(), paperSizeIndex: .threeInch)
// commands = PrinterFunctions.createTextReceiptData(emulation, localizeReceipts: localizeReceipts, utf8: false)
// Method (trying to print data from pdf url) : (createPdf417Data)
commands = ApiFunctions.createPdf417Data(emulation)
GlobalQueueManager.shared.serialQueue.async {
_ = Communication.sendCommands(commands,
portName: self.portName,
portSettings: self.portSettings,
timeout: 10000, // 10000mS!!!
completionHandler: { (communicationResult: CommunicationResult) in
DispatchQueue.main.async {
self.showSimpleAlert(title: "Communication Result",message: Communication.getCommunicationResultMessage(communicationResult),buttonTitle: "OK",buttonStyle: .cancel)
// self.navigationController!.popViewController(animated: true)
}
})
}
}
在类 ApiFunctions 中的位置
let globalPdfUrl:URL? = Bundle.main.url(forResource: "fake-store-receipt", withExtension: "pdf")
static func createPdf417Data(_ emulation: StarIoExtEmulation) -> Data {
let otherData = try! Data(contentsOf: globalPdfUrl!)
let builder: ISCBBuilder = StarIoExt.createCommandBuilder(emulation)
builder.beginDocument()
builder.appendPdf417Data(withAbsolutePosition: otherData, line: 0, column: 1, level: SCBPdf417Level.ECC0, module: 2, aspect: 2, position: 1)
builder.endDocument()
return builder.commands.copy() as! Data
}
但是打印的格式不正确。
希望快速详细的解决方案!!提前致谢。