Closed davidhole closed 6 months ago
I don't work for Star, but aren't those printer precisely graphics-only printers?
Hi @mortenbekditlevsen.
No the SDK has all sorts of methods for text, graphics, QR codes, barcodes, etc. All of these methods work well on other printers in the lineup (mPOP) but not on this printer.
It also works fine with these methods on other SDKs (StarPRNT)
In our POS system we've always been generating bitmaps of receipts for the graphics-only printers like the TSP1000 series. Also when using StarPRNT.
Please refer to similar discussions:
https://github.com/star-micronics/react-native-star-io10/issues/21
From one of the linked sources above:
"In particular, the TSP100 range does not have built-in font data, so is limited to printing graphically, and does not support the actionPrintText() method. Instead, if you require support for the TSP100 range, you will need to build up your document as images and add them to the print job with the actionPrintImage() method."
This is from a discussion about another printer driver, but it's not about the driver, it's about the fact that the printer does not have font data and thus only supports a subset of the available driver commands across all platforms / sdks.
I'm facing the same issue, is there any solution for this, or should be text edited like image and than printed? :/
That's what we're doing at my job: we basically have a document format which can be rendered to various destinations: HTML (for emailing), text (with hooks for various receipt printer integrations) and then UIView
s which we then render to images and print on graphics-only printers.
@mortenbekditlevsen Thank you for the explanation.
@davidhole @yellowMonkeyMediaDev
TSP100III series is a graphic-only printer. You need to use actionPrintImage. The provided project you can build uses actionPrintText only. So, TSP100III cannot print as you expected.
You can refer to Text-to-Graphic sample code. This sample includes a converting function from text to graphic so that you can use text to create printing data.
TSP100IV model supports actionPrintText.
I made an extension to PrinterBuilder
for convenience:
private let maxWidth = 570
extension StarIO10.StarXpandCommand.PrinterBuilder {
@objc public func actionPrintImageFromText(_ text: String, font: UIFont? = nil) -> Self {
actionPrintImage(createImageParameterFromText(text, font: font))
}
func createImageParameterFromText(_ text: String, font: UIFont?) -> StarXpandCommand.Printer.ImageParameter {
let width = maxWidth
let font = font ?? UIFont.monospacedSystemFont(ofSize: 24, weight: .medium)
let bitmap = createBitmapFromText(text, font: font, width: width)
return StarXpandCommand.Printer.ImageParameter(image: bitmap, width: width)
}
func createBitmapFromText(_ text: String, font: UIFont, width: Int) -> UIImage {
let attributeDic = NSDictionary(dictionary: [NSAttributedString.Key.font: font])
let widthCGF = CGFloat(width)
let stringDrawingOptions: NSStringDrawingOptions = [NSStringDrawingOptions.usesLineFragmentOrigin, NSStringDrawingOptions.truncatesLastVisibleLine]
let size: CGSize = (text.boundingRect(with: CGSize(width: widthCGF, height: 10_000), options: stringDrawingOptions, attributes: attributeDic as? [NSAttributedString.Key: Any], context: nil)).size
if UIScreen.main.responds(to: #selector(NSDecimalNumberBehaviors.scale)) {
if UIScreen.main.scale == 2.0 {
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
} else {
UIGraphicsBeginImageContext(size)
}
} else {
UIGraphicsBeginImageContext(size)
}
let context: CGContext = UIGraphicsGetCurrentContext()!
UIColor.white.set()
let rect = CGRect(x: 0, y: 0, width: size.width + 1, height: size.height + 1)
context.fill(rect)
let attributes = NSDictionary(dictionary: [NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.font: font])
text.draw(in: rect, withAttributes: attributes as? [NSAttributedString.Key: Any])
let imageToPrint: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return imageToPrint
}
}
It seems that this issue was resolved, so I am closing this Issue.
I have the same problem, but why can the Star Quick Setup Utility print the text clean and tidy. Converting to image cause ugly text words.
@MarsYoung This sample shows how to generate graphic data from text data. Does this sample show you a solution? If not, I would like to know the details of the problem. Please open a new Issue and describe the situation as accurately as possible.
Description
Whenever actionPrintText is used in a PrinterBuilder, it seems to be ignored in the final printout.
This can be seen using your included example app, with the final printout looking like this:
Your device where the bug occurs
Your printer
Your development environment
ProductName: macOS ProductVersion: 14.1.1 BuildVersion: 23B81
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A full printout including all text, as it appears on mPOP and other printers
Screenshots