Step 1 Generate Printing Data: Standard Function
Use PrinterBuilder to generate printing data.
PrinterBuilder provides you with useful methods to create printing data of receipts or labels.
The following is a printing result of a print sample available in the SDK. The procedure below describes the areas indicated by the numbers.
Created printing data will be used in Step 2.
Create printing data using the procedure below.
The sample code is available at the bottom of the page.
Also, refer to the sample application in the SDK.
1 Generate the StarXpandCommandBuilder instance, which is used to generate printing data.
Call the addDocument method to add DocumentBuilder, and then call the addPrinter method to add PrinterBuilder.
Call the PrinterBuilder methods to generate printing data.
var builder = new StarXpandCommand.StarXpandCommandBuilder(); builder.addDocument(new StarXpandCommand.DocumentBuilder() .addPrinter(new StarXpandCommand.PrinterBuilder()
2 Call the actionPrintImage method to instruct the printing of the image.
.actionPrintImage(new StarXpandCommand.Printer.ImageParameter("logo_01.png", 406))
3 Call the styleInternationalCharacter method to set the international character set to USA.
.styleInternationalCharacter(StarXpandCommand.Printer.InternationalCharacterType.Usa)
4 Call the styleCharacterSpace method to set the character spacing to 0 dots.
.styleCharacterSpace(0)
5 Call the styleAlignment method to set the alignment to center.
.styleAlignment(StarXpandCommand.Printer.Alignment.Center)
6 Call the actionPrintText method to instruct the printing of the character string. Print the character string in the argument.
.actionPrintText("Star Clothing Boutique\n" + "123 Star Road\n" + "City, State 12345\n" + "\n")
Memo
TSP100III series and TSP100IIU+ do 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 Models" of each method.
7 Call the add method to add a nested PrinterBuilder instance.
Character decoration set in a nested PrinterBuilder is valid only in that PrinterBuilder but not transferred to the parent PrinterBuilder.
Call the styleMagnification method to set the double height and width expansion for the character string.
.add(new StarXpandCommand.PrinterBuilder() .styleMagnification(new StarXpandCommand.MagnificationParameter(2, 2)) .actionPrintText(" $156.95\n")
8 Call the styleInvert method to set black and white inversion for the character string.
.styleInvert(true)
9 Call the actionPrintBarcode method to instruct the printing of the barcode. You can set the barcode in BarcodeParameter.
.actionPrintBarcode(new StarXpandCommand.Printer.BarcodeParameter('0123456', StarXpandCommand.Printer.BarcodeSymbology.Jan8) .setBarDots(3) .setBarRatioLevel(StarXpandCommand.Printer.BarcodeBarRatioLevel.Level0) .setHeight(5) .setPrintHri(true))
10 Call the actionFeedLine method to instruct the paper feeding of one line of data.
.actionFeedLine(1)
11 Call the actionPrintQRCode method to instruct the printing of the QR code. You can set the QR code in QRCodeParameter.
.actionPrintQRCode(new StarXpandCommand.Printer.QRCodeParameter('Hello World.\n') .setModel(StarXpandCommand.Printer.QRCodeModel.Model2) .setLevel(StarXpandCommand.Printer.QRCodeLevel.L) .setCellSize(8))
12 Call the actionCut method to instruct the paper cut (partial cut) while leaving one central point.
.actionCut(StarXpandCommand.Printer.CutType.Partial)
13 Call the getCommands method to acquire the printing data.
var commands = await builder.getCommands();
Sample code
var builder = new StarXpandCommand.StarXpandCommandBuilder();
builder.addDocument(new StarXpandCommand.DocumentBuilder()
.addPrinter(new StarXpandCommand.PrinterBuilder()
.actionPrintImage(new StarXpandCommand.Printer.ImageParameter("logo_01.png", 406))
.styleInternationalCharacter(StarXpandCommand.Printer.InternationalCharacterType.Usa)
.styleCharacterSpace(0)
.styleAlignment(StarXpandCommand.Printer.Alignment.Center)
.actionPrintText("Star Clothing Boutique\n" +
"123 Star Road\n" +
"City, State 12345\n" +
"\n")
.styleAlignment(StarXpandCommand.Printer.Alignment.Left)
.actionPrintText("Date:MM/DD/YYYY Time:HH:MM PM\n" +
"--------------------------------\n" +
"\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(new StarXpandCommand.PrinterBuilder()
.styleMagnification(new StarXpandCommand.MagnificationParameter(2, 2))
.actionPrintText(" $156.95\n")
)
.actionPrintText("--------------------------------\n" +
"\n" +
"Charge\n" +
"156.95\n" +
"Visa XXXX-XXXX-XXXX-0123\n" +
"\n")
.add(new StarXpandCommand.PrinterBuilder()
.styleInvert(true)
.actionPrintText("Refunds and Exchanges\n")
)
.actionPrintText("Within ")
.add(new StarXpandCommand.PrinterBuilder()
.styleUnderLine(true)
.actionPrintText("30 days")
)
.actionPrintText(" with receipt\n")
.actionPrintText("And tags attached\n" +
"\n")
.styleAlignment(StarXpandCommand.Printer.Alignment.Center)
.actionPrintBarcode(new StarXpandCommand.Printer.BarcodeParameter('0123456',
StarXpandCommand.Printer.BarcodeSymbology.Jan8)
.setBarDots(3)
.setBarRatioLevel(StarXpandCommand.Printer.BarcodeBarRatioLevel.Level0)
.setHeight(5)
.setPrintHri(true))
.actionFeedLine(1)
.actionPrintQRCode(new StarXpandCommand.Printer.QRCodeParameter('Hello World.\n')
.setModel(StarXpandCommand.Printer.QRCodeModel.Model2)
.setLevel(StarXpandCommand.Printer.QRCodeLevel.L)
.setCellSize(8))
.actionCut(StarXpandCommand.Printer.CutType.Partial)
)
);
var commands = await builder.getCommands();