微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以使用 StarPRNT-SDK-iOS-Swift 打印 pdf Url 数据内容?或者有没有其他方法可以从远程api响应打印数据?

如何解决是否可以使用 StarPRNT-SDK-iOS-Swift 打印 pdf Url 数据内容?或者有没有其他方法可以从远程api响应打印数据?

我正在关注用于集成的 git 演示示例:git : https://github.com/star-micronics/StarPRNT-SDK-iOS-Swift 我已经成功安装了 sdk,并且能够在 EnglishReceiptsImpl 类中打印样本。

现在,我正在尝试打印我在 api 响应中收到的内容

我很担心:

  1. 是否有任何直接方法可以转换/传递 pdf url 以打印内容
  2. 如何在“命令”中传递数据(Data/NSData)进行打印。

我正在使用/为 TSP650II 打印机型号工作。

我安装的 Pod 是:

// Swift SDK 的 Pods

 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
}

但打印的格式不正确。

enter image description here

希望得到快速详细的解决方案!!提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。