-
Re: Swift getGraphicsUtil().print() - no printing
Steven SiApr 5, 2018 7:44 PM (in response to Jun Meng)
Please use false for andIsInsideFormat: parameter, as we want to print out the signature as image independently.
try printer?.getGraphicsUtil().print (signatureImage!.cgImage!, atX: 0, atY: 0, withWidth: -1, withHeight: -1, andIsInsideFormat: false)
-
Re: Swift getGraphicsUtil().print() - no printing
Jun Meng Apr 6, 2018 6:53 AM (in response to Jun Meng)I tried false for andIsInsideFormat parameter. The signature still cannot be printed...
-
Re: Swift getGraphicsUtil().print() - no printing
Steven SiApr 13, 2018 7:01 AM (in response to Jun Meng)
The correct value for andIsInsideFormat is false in this case. I was able to see a blackbox got printed on the label, which means the API works. We may need to look into the code of signature capture part to see why we got a blackbox instead of the signature.
Update on 4/9/2018:
Today, I looked a little further into the code and made a few changes in getSignature() function in YPDrawSignatureView.swift. Now, the getSignature() is as below, by commenting out the part of stroke part (without redraw) , specifying the opaque with the current view's opaque value and using 0.0 for scaling parameter.
// Save the Signature as an UIImage public func getSignature(scale:CGFloat = 1) -> UIImage? { if !doesContainSignature { return nil } UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.isOpaque, 0.0) self.drawHierarchy(in: self.bounds, afterScreenUpdates: false) // self.strokeColor.setStroke() // self.path.stroke() let signature = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return signature }
Then, in printTransfer() function, we directly call getSignature(), i.e. bypassing getCroppedSignature() to simplify the debug.
// Print transfer with signature on mobile printer @IBAction func printTransfer(_ sender: UIButton) { let printer = ZebraPrinterUtil() if printer.serialNumber.isEmpty { let alert = UIAlertController(title: "Message", message: "No printer is available", preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: nil)) self.present(alert, animated: true, completion: nil) return } // Display warning message let alert = UIAlertController(title: "Print Transfer", message: printer.warningMessageBeforePrintContinuous, preferredStyle: .actionSheet) let OKAction = UIAlertAction(title: "Ok", style: .default) { (_) in // printer.printNewEvidenceTransfer(agencyName: self.agencyTextField.text!, contactPhone: self.phoneTextField.text!, personName: self.agencyNameTextField.text!, signatureImage: self.signatureView.getCroppedSignature()) printer.printNewEvidenceTransfer(agencyName: self.agencyTextField.text!, contactPhone: self.phoneTextField.text!, personName: self.agencyNameTextField.text!, signatureImage: self.signatureView.getSignature()) } let cancelAction = UIAlertAction(title: "Cancel", style: .default) alert.addAction(OKAction) alert.addAction(cancelAction) present(alert, animated: true) }
With these changes, we can successfully print out the signature as show in the screenshot below. Hope this helps.
-
Re: Swift getGraphicsUtil().print() - no printing
Jun Meng Apr 13, 2018 6:53 AM (in response to Steven Si)-
Re: Swift getGraphicsUtil().print() - no printing
Jun Meng Apr 13, 2018 6:54 AM (in response to Jun Meng)Attached is the project that prints signature with black background.
-
SignatureTest_20180412.zip 2.1 MB
-
Re: Swift getGraphicsUtil().print() - no printing
Steven SiApr 13, 2018 7:37 AM (in response to Jun Meng)
Attached is the full version of the Xcode project that prints the signature normally. It was a modified version based on the Xcode project you posted at the beginning of this thread.
-
SignatureTest_ok.zip 2.0 MB
-
Re: Swift getGraphicsUtil().print() - no printing
Jun Meng Apr 13, 2018 8:51 AM (in response to Steven Si)I see what's wrong on my side: the background color was not set in storyboard. With your code change, I can print signature now.
Thanks a lot!
-
-
-
-
-