star-micronics / StarXpand-SDK-iOS

StarXpand SDK for iOS is a software development kit for supporting application development for Star Micronics devices.
https://star-m.jp/starxpandsdk-oml.html
Other
27 stars 5 forks source link

print japanese text #19

Closed hoanhtdd closed 2 months ago

hoanhtdd commented 1 year ago

i have problem again with this text on mc_print3 :'アボカドアボカドアボ' , it doesn't print as i want but the text below prints correctly

hoanhtdd commented 1 year ago

IMG_20230821_170313

gare-bear commented 1 year ago

@hoanhtdd You need to enable Double-Byte characters to print Japanese. You can do this using the Star Quick Setup Utility; you can get it from the App Store.

Here's a brief guide to make this change

  1. Select your printer
  2. Go to Printer Settings -> Memory Switch Settings
  3. Change the Character Set to Multi Byte
  4. Change the MBCS Font Set to Japanese
  5. Click the Apply button to save the setting to your printer

From here, try to re-print the receipt and it should work 🤞

hoanhtdd commented 1 year ago

@hoanhtddBạn cần bật ký tự Double-Byte để in tiếng Nhật. Bạn có thể làm điều này bằng Star Quick Setup Utility; bạn có thể lấy nó từ App Store .

Dưới đây là hướng dẫn ngắn gọn để thực hiện thay đổi này

  1. Chọn máy in của bạn
  2. Chuyển đến Cài đặt máy in -> Cài đặt chuyển đổi bộ nhớ
  3. Thay đổi bộ ký tự thành Multi Byte
  4. Thay đổi bộ phông chữ MBCS sang tiếng Nhật
  5. Nhấp vào nút Áp dụng để lưu cài đặt vào máy in của bạn

Từ đây, hãy thử in lại biên lai và nó sẽ hoạt động 🤞

I'm using the printer's ios sdk, is there any way

hoanhtdd commented 1 year ago

I've been looking for places where I can set Japanese in the code, but it still doesn't work

.styleInternationalCharacter(.japan) .styleSecondPriorityCharacterEncoding(StarXpandCommand.Printer.CharacterEncodingType.japanese) .styleCJKCharacterPriority([StarXpandCommand.Printer.CJKCharacterType.japanese])

gare-bear commented 1 year ago

@hoanhtdd this needs to be done twice. This needs to be done in code to ensure the text is properly encoded. It also needs to be done as a printer setting to ensure the printer knows to expect double-byte Japanese characters.

Without both steps, you'll have an encoding mismatch similar to your current result.

gare-bear commented 1 year ago

@hoanhtdd any luck?

hoanhtdd commented 1 year ago

image I followed your instructions, when I open the Star Quick Setup Utility app, I see the default parameters as shown in the picture

Tatsuki-Yamamoto2731 commented 5 months ago

@hoanhtdd Is the problem solved? I changed the sample code to the following.

//
//  PrintingViewController.swift
//  StarXpandSDK
//
//  Copyright © 2021 Star Micronics. All rights reserved.
//

import UIKit
import StarIO10

class PrintingViewController: UIViewController {

    @IBOutlet weak var interfaceSelector: UISegmentedControl!
    @IBOutlet weak var identifierTextField: UITextField!
    @IBOutlet weak var printButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func touchUpPrintButton(_ sender: Any) {

        let identifier = identifierTextField.text ?? ""

        var selectedInterface: InterfaceType = InterfaceType.unknown
        switch interfaceSelector.selectedSegmentIndex {
        case 0:
            selectedInterface = InterfaceType.lan
        case 1:
            selectedInterface = InterfaceType.bluetooth
        case 2:
            selectedInterface = InterfaceType.bluetoothLE
        case 3:
            selectedInterface = InterfaceType.usb
        default:
            return
        }

        let starConnectionSettings = StarConnectionSettings(interfaceType: selectedInterface,
                                                            identifier: identifier)

        let printer = StarPrinter(starConnectionSettings)

        guard let logo = UIImage(named: "logo_01") else {
            print("Failed to load \"logo_01.png\".")
            return
        }

        // TSP100III series does not support actionPrintText because these products are graphics-only printers.
        // Please use the actionPrintImage method to create printing data for these products.
        // For other available methods, please also refer to "Supported Model" of each method.
        // https://star-m.jp/products/s_print/sdk/starxpand/manual/en/ios-swift-api-reference/star-xpand-command/printer-builder/action-print-image.html
        let builder = StarXpandCommand.StarXpandCommandBuilder()
        _ = builder.addDocument(StarXpandCommand.DocumentBuilder()
            // To open a cash drawer, comment out the following code.
//          .addDrawer(StarXpandCommand.DrawerBuilder()
//              .actionOpen(StarXpandCommand.Drawer.OpenParameter())
//          )
            .addPrinter(StarXpandCommand.PrinterBuilder()
                .actionPrintText("アボカドアボカドアボ\n" +
                                 "\n" +
                                 "\n" +
                                 "\n")
                .actionCut(StarXpandCommand.Printer.CutType.partial)
            )
        )

        let command = builder.getCommands()

        Task {
            do {
                try await printer.open()
                defer {
                    Task {
                        await printer.close()
                    }
                }

                try await printer.print(command: command)

                print("Success")
            } catch let error {
                print("Error: \(error)")
            }
        }
    }
}

Printer settings: the same as your settings

Printing result: image

If you haven't solved the problem, could you please try this sample?