StarXpand SDK for iOS / Android 開発者向けマニュアル Ver. 1.7.0

最終更新日: 2024年 6月 24日

Step.1 印刷データの生成 : 標準機能

手順はOSによって異なります。 表示するOSを選択してください。

iOS Android


PrinterBuilderを使って、印刷データを生成します。
PrinterBuilderにはレシートやラベルの印刷データを生成するための便利なメソッドが用意されています。



以下は、SDKで用意されている印刷サンプルの印字結果です。番号の個所について説明しています。
作成した印刷データはStep2で使用します。

以下の手順を参考に、印刷データを作成してください。
ページ下部にサンプルコードがあります。 また、SDKのサンプルアプリも参考にしてください。

1印刷データを生成するために使用するStarXpandCommandBuilderインスタンスを生成します。
addDocumentメソッドを呼び出してDocumentBuilderを追加し、 addPrinterメソッドを呼び出してPrinterBuilderを追加します。
PrinterBuilderの各メソッドを呼び出して、印刷データを生成していきます。

let builder = StarXpandCommand.StarXpandCommandBuilder()
_ = builder.addDocument(StarXpandCommand.DocumentBuilder.init()
                            .addPrinter(StarXpandCommand.PrinterBuilder()

2画像の印刷をするためactionPrintImageメソッドを呼び出します。

.actionPrintImage(StarXpandCommand.Printer.ImageParameter(image: logo, width: 406))

3国際文字セットをUSAに設定するためstyleInternationalCharacterメソッドを呼び出します。

.styleInternationalCharacter(.usa)

4文字間スペースを0ドットに設定するためstyleCharacterSpaceメソッドを呼び出します。

.styleCharacterSpace(0)

5左右位置を中央揃えに設定するためstyleAlignmentメソッドを呼び出します。

.styleAlignment(.center)

6文字列の印刷を指示するためactionPrintTextメソッドを呼び出します。

.actionPrintText("Star Clothing Boutique\n" +
                 "123 Star Road\n" +
                 "City, State 12345\n" +
                 "\n")

Memo
TSP100IIIシリーズとTSP100IIU+は画像印刷専用プリンターのため、actionPrintTextメソッドはサポートしていません。
これらのプリンターの印刷データを生成するためにはactionPrintImageメソッドをご利用ください。その他利用可能なメソッドは各メソッドの"Supported Model"を参照ください。

7addメソッドを呼び出して、入れ子のPrinterBuilderインスタンスを追加することができます。
入れ子のPrinterBuilderで設定された文字装飾は、そのPrinterBuilder内でのみ有効となり、親のPrinterBuilderには引き継がれません。
文字列の縦横2倍拡大を設定するためstyleMagnificationメソッドを呼び出します。

.add(
    StarXpandCommand.PrinterBuilder()
        .styleMagnification(StarXpandCommand.MagnificationParameter(width: 2, height: 2))
        .actionPrintText("   $156.95\n")
)

8文字列の白黒反転を設定するためstyleInvertメソッドを呼び出します。

.styleInvert(true)

9バーコードの印刷を支持するためactionPrintBarcodeメソッドを呼び出します。バーコードの設定はBarcodeParameterにて行います。

.actionPrintBarcode(StarXpandCommand.Printer.BarcodeParameter(content: "0123456", symbology: .jan8)
                        .setBarDots(3)
                        .setHeight(5)
                        .setPrintHRI(true))

101行分の紙送りを指示するためactionFeedLineメソッドを呼び出します。

.actionFeedLine(1)

11QRコードの印刷を指示するためactionPrintQRCodeメソッドを呼び出します。QRコードの設定はQRCodeParameterにて行います。

.actionPrintQRCode(StarXpandCommand.Printer.QRCodeParameter(content: "Hello World.\n")
                    .setLevel(.l)
                    .setCellSize(8))

12中央一点残しの用紙カットを指示するためactionCutメソッドを呼び出します。

.actionCut(StarXpandCommand.Printer.CutType.partial)))

13印刷データを取得するためgetCommandsメソッドを呼び出します。

let command = builder.getCommands()
サンプルコード

let builder = StarXpandCommand.StarXpandCommandBuilder()
_ = builder.addDocument(StarXpandCommand.DocumentBuilder.init()
              .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)))
        
let command = builder.getCommands()

PrinterBuilderを使って、印刷データを生成します。
PrinterBuilderにはレシートやラベルの印刷データを生成するための便利なメソッドが用意されています。



以下は、SDKで用意されている印刷サンプルの印字結果です。番号の個所について説明しています。
作成した印刷データはStep2で使用します。

以下の手順を参考に、印刷データを作成してください。
ページ下部にサンプルコードがあります。 また、SDKのサンプルアプリも参考にしてください。

1印刷データを生成するためのStarXpandCommandBuilderインスタンスを生成します。
addDocumentメソッドを呼び出してDocumentBuilderを追加し、 addPrinterメソッドを呼び出してPrinterBuilderを追加します。
PrinterBuilderの各メソッドを呼び出して、印刷データを生成していきます。

val builder = StarXpandCommandBuilder()
builder.addDocument(
    DocumentBuilder()
         .addPrinter(
              PrinterBuilder()

2画像の印刷を指示するためactionPrintImageメソッドを呼び出します。

.actionPrintImage(ImageParameter(logo, 406))

3国際文字セットをUSBに設定するためstyleInternationalCharacterメソッドを呼び出します。

.styleInternationalCharacter(InternationalCharacterType.Usa)

4文字間スペースを0ドットに設定するためstyleCharacterSpaceメソッドを呼び出します。

.styleCharacterSpace(0.0)

5左右位置を中央揃えに設定するためstyleAlignmentメソッドを呼び出します。

.styleAlignment(Alignment.Center)

6文字列の印刷を指示するためactionPrintTextメソッドを呼び出します。

.actionPrintText(
    "Star Clothing Boutique\n" +
            "123 Star Road\n" +
            "City, State 12345\n" +
            "\n"
)

Memo
TSP100IIIシリーズとTSP100IIU+は画像印刷専用プリンターのため、actionPrintTextメソッドはサポートしていません。
これらのプリンターの印刷データを生成するためにはactionPrintImageメソッドをご利用ください。その他利用可能なメソッドは各メソッドの"Supported Model"を参照ください。

7addメソッドを呼び出して、入れ子のPrinterBuilderインスタンスを追加することができます。
入れ子のPrinterBuilderで設定された文字装飾は、そのPrinterBuilder内でのみ有効となり、親のPrinterBuilderには引き継がれません。
文字列の縦横2倍拡大を設定するためstyleMagnificationメソッドを呼び出します。

.add(
    PrinterBuilder()
        .styleMagnification(MagnificationParameter(2, 2))
        .actionPrintText("   $156.95\n")
)

8文字列の白黒反転を設定するためstyleInvertメソッドを呼び出します。

.styleInvert(true)

9バーコードの印刷を指示するためactionPrintBarcodeメソッドを呼び出します。バーコードの設定はBarcodeParameterにて行います。

.actionPrintBarcode(
    BarcodeParameter("0123456", BarcodeSymbology.Jan8)
        .setBarDots(3)
        .setHeight(5.0)
        .setPrintHri(true)
)

101行分の紙送りを指示するためactionFeedLineメソッドを呼び出します。

.actionFeedLine(1)

11QRコードの印刷を指示するためactionPrintQRCodeメソッドを呼び出します。QRコードの設定はQRCodeParameterにて行います。

.actionPrintQRCode(
    QRCodeParameter("Hello, World\n")
        .setLevel(QRCodeLevel.L)
        .setCellSize(8)
)

12中央一点残しの用紙カットを指示するためactionCutメソッドを呼び出します。

.actionCut(CutType.Partial)
)
)

13印刷データを取得するためgetCommandsメソッドを呼び出します。

val commands = builder.getCommands()
サンプルコード

val builder = StarXpandCommandBuilder()
builder.addDocument(
    DocumentBuilder()
         .addPrinter(
              PrinterBuilder()
                  .actionPrintImage(ImageParameter(logo, 406))
                  .styleInternationalCharacter(InternationalCharacterType.Usa)
                  .styleCharacterSpace(0.0)
                  .styleAlignment(Alignment.Center)
                  .actionPrintText(
                      "Star Clothing Boutique\n" +
                              "123 Star Road\n" +
                              "City, State 12345\n" +
                              "\n"
                  )
                  .styleAlignment(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(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)
         )
)
                  
val commands = builder.getCommands()