I have made an app, and the app needs to print a receipt. I have a star TSP650 II thermal printer that supports AirPrint. I can print and that works fine. The use of previous selected printer also works fine.
However, it cuts automatically after 140mm, and sometime my receipts can get 2 or 3 timers longer.
How can I programmatically set the paper length ?
func SelecteDefaultPrinter(){
let printerPicker = UIPrinterPickerController(initiallySelectedPrinter: nil)
printerPicker.present(from: CGRect(x: 0, y: -100, width: 600, height: 500), in: self.view, animated: true) { (printerPicker, userDidSelect, error) in
if userDidSelect {
//Here get the selected UIPrinter
self.defaultPrinter = printerPicker.selectedPrinter!
let js="storeprinter('\(printerPicker.selectedPrinter!.displayName)','\(printerPicker.selectedPrinter!.url)');"
self.webView.evaluateJavaScript(js, completionHandler: nil)
self.printerURL = printerPicker.selectedPrinter!.url
self.user!.printerurl = printerPicker.selectedPrinter!.url.absoluteString
print(self.user!)
// self.printText()
}
}
}
func printText() {
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = "print Job"
printController.printInfo = printInfo
let formatter = UIMarkupTextPrintFormatter(markupText: html)
formatter.perPageContentInsets = UIEdgeInsets(top: 2, left: 5, bottom: 0, right: 5)
printController.printFormatter = formatter
if(printerURL == URL(string: "http://notset.local")) {
print("no printer selected");
printController.present(animated: true, completionHandler: nil)
} else {
let currentPrinter = UIPrinter(url: printerURL!)
printController.print(to: currentPrinter, completionHandler: {(controller, success, error) -> Void in
if success {
debugPrint("Printing Completed.")
} else {
debugPrint("Printing Failed.")
}
})
}
}
I am fairly new to the whole iOS / SWIFT, so please help.