Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSP100IIILAN / TSP143LAN not printing text, only images #24

Closed
davidhole opened this issue Nov 28, 2023 · 10 comments
Closed

TSP100IIILAN / TSP143LAN not printing text, only images #24

davidhole opened this issue Nov 28, 2023 · 10 comments
Labels
Status: question Further information from Issue contributor is requested

Comments

@davidhole
Copy link

davidhole commented Nov 28, 2023

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:
IMG_9100

Your device where the bug occurs

  • Device:
    iPhone 15 Pro Max
  • OS:
    iOS 17.1.1

Your printer

  • Model Names:
    TSP100IIILAN / TSP143LAN
  • Interface:
    Ethernet

Your development environment

ProductName: macOS
ProductVersion: 14.1.1
BuildVersion: 23B81

To Reproduce

Steps to reproduce the behavior:

  1. Open the included example app from this repo
  2. Click Discover to find printer MAC
  3. Go back and select Print.
  4. Enter MAC in address (adding in colons)
  5. Press Print
  6. Only images print as part of test print, no text is printed.

Expected behavior

A full printout including all text, as it appears on mPOP and other printers

Screenshots

IMG_9100

@davidhole davidhole added the Status: triage Start out by looking at issues label Nov 28, 2023
@mortenbekditlevsen
Copy link

I don't work for Star, but aren't those printer precisely graphics-only printers?

@davidhole
Copy link
Author

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)

@mortenbekditlevsen
Copy link

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:

star-micronics/react-native-star-io10#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.

@yellowMonkeyMediaDev
Copy link

yellowMonkeyMediaDev commented Dec 10, 2023

I'm facing the same issue, is there any solution for this, or should be text edited like image and than printed? :/

@mortenbekditlevsen
Copy link

mortenbekditlevsen commented Dec 10, 2023

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 UIViews which we then render to images and print on graphics-only printers.

@YuzoKato
Copy link

@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.

@BryanJBryce
Copy link

BryanJBryce commented Jan 24, 2024

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
    }
}

@Tatsuki-Yamamoto2731 Tatsuki-Yamamoto2731 added Status: question Further information from Issue contributor is requested and removed Status: triage Start out by looking at issues labels Mar 28, 2024
@Tatsuki-Yamamoto2731
Copy link

It seems that this issue was resolved, so I am closing this Issue.

@MarsYoung
Copy link

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.

@Tatsuki-Yamamoto2731
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: question Further information from Issue contributor is requested
Projects
None yet
Development

No branches or pull requests

7 participants