StarXpand SDK for iOS/Android Developer's Manual Ver. 1.14.0

Last update: Sep. 15, 2026

Generate Printing Data

The procedure and the reference vary depending on the OS. Select the OS to display.

iOS Android


This section describes the structures of StarPRNT SDK and StarXpand SDK for printing data generation operations.

Understand the differences between these SDKs before migrating to StarXpand SDK.

StarPRNT SDK

  • 1. Determine the printer emulation.
  • 2. Generate an ISCBBuilder class instance.
  • 3. Execute the beginDocument() method at the beginning of the printing data.
  • 4. Use the append... method to add print text and images, parameters such as character encoding and international characters, and a paper-cut command.
  • 5. Execute the endDocument() method at the end.
  • 6. Retrieve the printing data from the commands property.
  • 7. Use the write() method of the SMPort class to send the retrieved printing data to the printer.

Sample code (GitHub)
Implementation examples are available at the bottom of the page.



StarXpand SDK

  • 1. Generate a StarXpandCommandBuilder class instance.
  • 2. Execute the addDocument() method of the StarXpandCommandBuilder class.
    Generate a DocumentBuilder class instance and pass it as an argument.
  • 3. Execute the addPrinter() method of the StarXpandCommandBuilder instance generated in Step 2.
    Generate a PrinterBuilder class instance and pass it as an argument.
  • 4. Use the following methods of the PrinterBuilder instance generated in Step 3 to add printing content and decorations.
    Print processes, such as print text, barcode, and paper cut: action...() method (Example: actionPrintText())
    Parameters, such as international characters, underline, and center alignment: style...() method (Example: styleCharacterSpace())
    Adding a child PrinterBuilder to a parent PrinterBuilder: add() method
  • 5. Use the getCommands() method to retrieve the printing data.
  • 6. Use the print(command:) method to send the retrieved printing data to the printer.

Sample code (GitHub)
Implementation examples are available at the bottom of the page.



Comparison between the two SDKs

StarPRNT SDK StarXpand SDK
Printer emulation [1] Manually specified Automatically determined
Character encoding Manually specified Automatically determined
Decoration clearing [2] Must be explicitly cleared Automatically cleared
Printing data Binary Text
Template printing Unsupported Supported
Black mark Back only Front and back

[1] In StarXpand SDK, the printer emulation is automatically determined. Therefore, even when multiple printer models are supported, there is no need to explicitly specify the emulation for each model.

[2] In StarPRNT SDK, if text decorations have been applied, they must be explicitly cleared. In StarXpand SDK, decorations are automatically cleared because PrinterBuilder can be organized in a parent-child hierarchy, and decorations applied to a child do not affect its parent.




Implementation examples

StarPRNT SDK

private func createPrinterCommand(emulation: StarIoExtEmulation, utf8: Bool ) -> Data {

        let builder: ISCBBuilder = StarIoExt.createCommandBuilder(emulation)
        
        builder.beginDocument()
        
        if let logo = UIImage(named: "logo_01") {
            builder.appendBitmap(logo, diffusion: false, width: 406, bothScale: true)
        }
        builder.append(SCBInternationalType.USA)
        
        let encoding: String.Encoding
        
        if utf8 == true {
            encoding = String.Encoding.utf8
            
            builder.append(SCBCodePageType.UTF8)
        }
        else {
            encoding = String.Encoding.ascii
            
            builder.append(SCBCodePageType.CP998)
        }
        
        builder.appendCharacterSpace(0)
        
        builder.appendAlignment(SCBAlignmentPosition.center)
        builder.append(("Star Clothing Boutique\n" +
                        "123 Star Road\n" +
                        "City, State 12345\n" +
                        "\n").data(using: encoding))
        
        builder.appendAlignment(SCBAlignmentPosition.left)
        builder.append(("Date:MM/DD/YYYY    Time:HH:MM PM\n" +
                        "--------------------------------\n" +
                        "\n").data(using: encoding))
        
        builder.appendEmphasis(true)
        builder.append(("SALE \n").data(using: encoding))
        builder.appendEmphasis(false)
        
        builder.append(("SKU         Description    Total\n" +
                        "300678566   PLAIN T-SHIRT  10.99\n" +
                        "300692003   BLACK DENIM    29.99\n" +
                        "300651148   BLUE DENIM     29.99\n" +
                        "300642980   STRIPED DRESS  49.99\n" +
                        "300638471   BLACK BOOTS    35.99\n" +
                        "\n" +
                        "Subtotal                  156.95\n" +
                        "Tax                         0.00\n" +
                        "--------------------------------\n").data(using: encoding))
        builder.append(("Total     ").data(using: encoding))
        
        builder.appendMultiple(2,height:2)
        builder.append(("   $156.95\n").data(using: encoding))
        builder.appendMultiple(1,height:1)
        
        builder.append(("--------------------------------\n" +
                        "\n" +
                        "Charge\n" +
                        "156.95\n" +
                        "Visa XXXX-XXXX-XXXX-0123\n" +
                        "\n").data(using: encoding))
        
        builder.appendInvert(true)
        builder.append(("Refunds and Exchanges\n").data(using: encoding))
        builder.appendInvert(false)
        
        builder.append(("Within ").data(using: encoding))
        
        builder.appendUnderLine(true)
        builder.append(("30 days").data(using: encoding))
        builder.appendUnderLine(false)
        
        builder.append((" with receipt\n" +
                        "And tags attached\n" +
                        "\n").data(using: encoding))
        
        builder.appendAlignment(SCBAlignmentPosition.center)
        builder.appendBarcodeData("0123456".data(using: String.Encoding.ascii), symbology: SCBBarcodeSymbology.JAN8, width: SCBBarcodeWidth.mode2, height: 40, hri: true)
        
        builder.appendLineFeed(1)
        builder.appendQrCodeData("Hello World.\n".data(using: String.Encoding.ascii), model: SCBQrCodeModel.no1, level: SCBQrCodeLevel.L , cell: 8)
        
        builder.appendCutPaper(SCBCutPaperAction.partialCutWithFeed)
        builder.endDocument()
        
        let command = builder.commands.copy() as! Data
        return command
    }

StarXpand SDK

    private func createPrinterCommand() -> String {
	guard let logo = UIImage(named: "logo_01") else {
            print("Failed to load \"logo_01.png\".")
            return ""
        }
        
        let builder = StarXpandCommand.StarXpandCommandBuilder()
        _ = builder.addDocument(StarXpandCommand.DocumentBuilder()
            .addPrinter(StarXpandCommand.PrinterBuilder()
                .actionPrintImage(StarXpandCommand.Printer.ImageParameter(image: logo, width: 406))
                .styleInternationalCharacter(.usa)
                .styleCharacterSpace(0)
                .styleAlignment(.center)
                .actionPrintText("Star Clothing Boutique\n" +
                                 "123 Star Road\n" +
                                 "City, State 12345\n" +
                                 "\n")
                .styleAlignment(.left)
                .actionPrintText("Date:MM/DD/YYYY    Time:HH:MM PM\n" +
                                 "--------------------------------\n" +
                                 "\n")
                .add(
                    StarXpandCommand.PrinterBuilder()
                        .styleBold(true)
                        .actionPrintText("SALE \n")
                    )
                .actionPrintText("SKU         Description    Total\n" +
                                 "300678566   PLAIN T-SHIRT  10.99\n" +
                                 "300692003   BLACK DENIM    29.99\n" +
                                 "300651148   BLUE DENIM     29.99\n" +
                                 "300642980   STRIPED DRESS  49.99\n" +
                                 "300638471   BLACK BOOTS    35.99\n" +
                                 "\n" +
                                 "Subtotal                  156.95\n" +
                                 "Tax                         0.00\n" +
                                 "--------------------------------\n")
                .actionPrintText("Total     ")
                .add(
                    StarXpandCommand.PrinterBuilder()
                        .styleMagnification(StarXpandCommand.MagnificationParameter(width: 2, height: 2))
                        .actionPrintText("   $156.95\n")
                    )
                .actionPrintText("--------------------------------\n" +
                                 "\n" +
                                 "Charge\n" +
                                 "156.95\n" +
                                 "Visa XXXX-XXXX-XXXX-0123\n" +
                                 "\n")
                .add(
                    StarXpandCommand.PrinterBuilder()
                        .styleInvert(true)
                        .actionPrintText("Refunds and Exchanges\n")
                    )
                .actionPrintText("Within ")
                .add(
                    StarXpandCommand.PrinterBuilder()
                        .styleUnderLine(true)
                        .actionPrintText("30 days")
                    )
                .actionPrintText(" with receipt\n" +
                                 "And tags attached\n" +
                                 "\n")
                .styleAlignment(.center)
                .actionPrintBarcode(
                    StarXpandCommand.Printer.BarcodeParameter(content: "0123456", symbology: .jan8)
                        .setBarDots(3)
                        .setHeight(5)
                        .setPrintHRI(true)
                )
                .actionFeedLine(1)
                .actionPrintQRCode(
                    StarXpandCommand.Printer.QRCodeParameter(content: "Hello World.\n")
                        .setLevel(.l)
                        .setCellSize(8)
                )
                .actionCut(StarXpandCommand.Printer.CutType.partial)
            )
        )
        return builder.getCommands()
    }

Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.

This section describes the structures of StarPRNT SDK and StarXpand SDK for printing data generation operations.

Understand the differences between these SDKs before migrating to StarXpand SDK.

StarPRNT SDK

  • 1. Determine the printer emulation.
  • 2. Generate an ICommandBuilder class instance.
  • 3. Execute the beginDocument() method at the beginning of the printing data.
  • 4. Use the append... method to add print text and images, parameters such as character encoding and international characters, and a paper-cut command.
  • 5. Execute the endDocument() method at the end.
  • 6. Use the getCommands() method to retrieve the printing data.
  • 7. Use the writePort() method of the StarIOPort class to send the retrieved printing data to the printer.

Sample code (GitHub)
Implementation examples are available at the bottom of the page.



StarXpand SDK

  • 1. Generate a StarXpandCommandBuilder class instance.
  • 2. Execute the addDocument() method of the StarXpandCommandBuilder class.
    Generate a DocumentBuilder class instance and pass it as an argument.
  • 3. Execute the addPrinter() method of the StarXpandCommandBuilder instance generated in Step 2.
    Generate a PrinterBuilder class instance and pass it as an argument.
  • 4. Use the following methods of the PrinterBuilder instance generated in Step 3 to add printing content and decorations.
    Print processes, such as print text, barcode, and paper cut: action...() method (Example: actionPrintText())
    Parameters, such as international characters, underline, and center alignment: style...() method (Example: styleCharacterSpace())
    Adding a child PrinterBuilder to a parent PrinterBuilder: add() method
  • 5. Use the getCommands() method to retrieve the printing data.
  • 6. Use the printAsync(command) method to send the retrieved printing data to the printer.

Sample code (GitHub)
Implementation examples are available at the bottom of the page.



Comparison between the two SDKs

StarPRNT SDK StarXpand SDK
Printer emulation [1] Manually specified Automatically determined
Character encoding Manually specified Automatically determined
Decoration clearing [2] Must be explicitly cleared Automatically cleared
Printing data Binary Text
Template printing Unsupported Supported
Black mark Back only Front and back

[1] In StarXpand SDK, the printer emulation is automatically determined. Therefore, even when multiple printer models are supported, there is no need to explicitly specify the emulation for each model.

[2] In StarPRNT SDK, if text decorations have been applied, they must be explicitly cleared. In StarXpand SDK, decorations are automatically cleared because PrinterBuilder can be organized in a parent-child hierarchy, and decorations applied to a child do not affect its parent.




Implementation examples

StarPRNT SDK

private fun createPrinterCommand(
    emulation: StarIoExt.Emulation,
    utf8: Boolean,
    context: Context
): ByteArray {
    val builder = StarIoExt.createCommandBuilder(emulation)
    builder.beginDocument()

    val logo = BitmapFactory.decodeResource(context.resources, R.drawable.logo_01)
    builder.appendBitmap(logo, false, 406, true)

    builder.appendInternational(ICommandBuilder.InternationalType.USA)

    val encoding = if (utf8) {
        builder.appendCodePage(ICommandBuilder.CodePageType.UTF8)
        Charsets.UTF_8
    } else {
        builder.appendCodePage(ICommandBuilder.CodePageType.CP998)
        Charsets.US_ASCII
    }

    builder.appendCharacterSpace(0)
    builder.appendAlignment(ICommandBuilder.AlignmentPosition.Center)
    builder.append(
        "Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n".toByteArray(
            encoding
        )
    )

    builder.appendAlignment(ICommandBuilder.AlignmentPosition.Left)
    builder.append(
        "Date:MM/DD/YYYY    Time:HH:MM PM\n--------------------------------\n\n".toByteArray(
            encoding
        )
    )

    builder.appendEmphasis(true)
    builder.append("SALE \n".toByteArray(encoding))
    builder.appendEmphasis(false)

    builder.append((
            "SKU         Description    Total\n" +
            "300678566   PLAIN T-SHIRT  10.99\n" +
            "300692003   BLACK DENIM    29.99\n" +
            "300651148   BLUE DENIM     29.99\n" +
            "300642980   STRIPED DRESS  49.99\n" +
            "300638471   BLACK BOOTS    35.99\n" +
            "\n" +
            "Subtotal                  156.95\n" +
            "Tax                         0.00\n" +
            "--------------------------------\n").toByteArray(encoding)
    )
    builder.append("Total     ".toByteArray(encoding))

    builder.appendMultiple(2, 2)
    builder.append("   $156.95\n".toByteArray(encoding))
    builder.appendMultiple(1, 1)

    builder.append((
            "--------------------------------\n" +
            "\n" +
            "Charge\n" +
            "156.95\n" +
            "Visa XXXX-XXXX-XXXX-0123\n" +
            "\n").toByteArray(encoding)
    )

    builder.appendInvert(true)
    builder.append("Refunds and Exchanges\n".toByteArray(encoding))
    builder.appendInvert(false)

    builder.append("Within ".toByteArray(encoding))
    builder.appendUnderLine(true)
    builder.append("30 days".toByteArray(encoding))
    builder.appendUnderLine(false)
    builder.append(" with receipt\nAnd tags attached\n\n".toByteArray(encoding))

    builder.appendAlignment(ICommandBuilder.AlignmentPosition.Center)
    builder.appendBarcode(
        "0123456".toByteArray(Charsets.US_ASCII),
        ICommandBuilder.BarcodeSymbology.JAN8,
        ICommandBuilder.BarcodeWidth.Mode2,
        40,
        true
    )

    builder.appendLineFeed(1)
    builder.appendQrCode(
        "Hello World.\n".toByteArray(Charsets.US_ASCII),
        ICommandBuilder.QrCodeModel.No1,
        ICommandBuilder.QrCodeLevel.L,
        8
    )

    builder.appendCutPaper(ICommandBuilder.CutPaperAction.PartialCutWithFeed)
    builder.endDocument()
    return builder.commands
}

StarXpand SDK

    private fun createPrinterCommand(): String {
    val logo = BitmapFactory.decodeResource(resources, R.drawable.logo_01)

    val builder = StarXpandCommandBuilder()
    builder.addDocument(
        DocumentBuilder()
            .addPrinter(
                PrinterBuilder()
                    .actionPrintImage(ImageParameter(logo, 406))
                    .styleInternationalCharacter(InternationalCharacterType.Usa)
                    .styleCharacterSpace(0.0)
                    .styleAlignment(com.starmicronics.stario10.starxpandcommand.printer.Alignment.Center)
                    .actionPrintText(
                        "Star Clothing Boutique\n" +
                        "123 Star Road\n" +
                        "City, State 12345\n" +
                        "\n",
                    ).styleAlignment(com.starmicronics.stario10.starxpandcommand.printer.Alignment.Left)
                    .actionPrintText(
                        "Date:MM/DD/YYYY    Time:HH:MM PM\n" +
                        "--------------------------------\n" +
                        "\n",
                    ).add(
                        PrinterBuilder()
                            .styleBold(true)
                            .actionPrintText("SALE\n"),
                    ).actionPrintText(
                        "SKU         Description    Total\n" +
                        "300678566   PLAIN T-SHIRT  10.99\n" +
                        "300692003   BLACK DENIM    29.99\n" +
                        "300651148   BLUE DENIM     29.99\n" +
                        "300642980   STRIPED DRESS  49.99\n" +
                        "300638471   BLACK BOOTS    35.99\n" +
                        "\n" +
                        "Subtotal                  156.95\n" +
                        "Tax                         0.00\n" +
                        "--------------------------------\n",
                    ).actionPrintText("Total     ")
                    .add(
                        PrinterBuilder()
                            .styleMagnification(MagnificationParameter(2, 2))
                            .actionPrintText("   $156.95\n"),
                    ).actionPrintText(
                        "--------------------------------\n" +
                        "\n" +
                        "Charge\n" +
                        "156.95\n" +
                        "Visa XXXX-XXXX-XXXX-0123\n" +
                        "\n",
                    ).add(
                        PrinterBuilder()
                            .styleInvert(true)
                            .actionPrintText("Refunds and Exchanges\n"),
                    ).actionPrintText("Within ")
                    .add(
                        PrinterBuilder()
                            .styleUnderLine(true)
                            .actionPrintText("30 days"),
                    ).actionPrintText(" with receipt\n")
                    .actionPrintText(
                        "And tags attached\n" +
                        "\n",
                    ).styleAlignment(com.starmicronics.stario10.starxpandcommand.printer.Alignment.Center)
                    .actionPrintBarcode(
                        BarcodeParameter("0123456", BarcodeSymbology.Jan8)
                            .setBarDots(3)
                            .setHeight(5.0)
                            .setPrintHri(true),
                    ).actionFeedLine(1)
                    .actionPrintQRCode(
                        QRCodeParameter("Hello, World\n")
                            .setLevel(QRCodeLevel.L)
                            .setCellSize(8),
                    ).actionCut(CutType.Partial),
        ),
    )
    return builder.getCommands()
}

Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.