Print API: Star Micronics Printers

The Star Printer API allows printing of different bar codes, QR-codes, simple text, specific HTML elements, and full webpages to Star Micronics thermal printers. In addition, the Star Printer API can return information about the results of a specific printing job and the status of the connected Star printer.

Supported Star Micronics printers include:

  • TSP100 series
  • TSP650 series
  • TSP700 series
  • TSP800 series
  • mPOP
  • mC-Print2
  • mC-Print3

This API can also be used to control cash drawers and barcode readers connected through an attached Star printer.

General Functions

Printing Functions

Cash Drawer Functions

Barcode Scanner Functions

Callbacks

Related Settings

Deprecated Calls

Requirements

  • Access JavaScript API
    • By Import - recommended, works both online & offline, requires inclusion of kiosk_functions.js prior to any of the following calls.
    • By Injection - only works offline, may not be available 'onload' event.
  • Printing
    • Star Micronics Printer = On
    • Star Micronics Printer Settings > Select Printer or enter Port Name
      • if connecting via Wi-Fi = 'TCP:' + the IP address of the printer
      • if connecting via Bluetooth = 'BT:' + name assigned to printer
    • Star Micronics Printer Settings > Port Settings = 9100, unless specifically changed during printer set-up
  • Connection to a supported Star Micronics printer

Sample Code

This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.  

To run sample code, set the app's homepage to http://www.kioskproapp.com/star-print

Download Sample Code


kp_StarPrinter_requestStateOfSupporting

This function checks whether the printing to a Star Micronics printer is enabled in Kiosk Pro's settings.

Format
kp_StarPrinter_requestStateOfSupporting();
		

Status

Kiosk Pro will immediately call kp_StarPrinter_stateOfSupportingDidChange with the current status.


kp_StarPrinter_requestStatusOfPrinter

This function requests the current status of the Star printer.

Format
kp_StarPrinter_requestStatusOfPrinter();
		

Status

Kiosk Pro will immediately call kp_StarPrinter_statusOfPrinterDidChange once for each of the six possible error states.


kp_StarPrinter_startBatchPrinting

This function merges multiple printer functions into one print command to send to the printer. This is helpful if you see delays between calls.

Format
kp_StarPrinter_startBatchPrinting(JSON.stringify(batch));
		
Parameters

JSON-scheme representing a set of descriptions of StarPrinter API functions.

  • {"barcode":{"symbology":"code39", "code":"1234567890", "cutPaper":false}},
  • {"newLF":{"cutPaper":false}},
  • {"qrcode":{"code":"1234567890", "cutPaper":false}},
  • {"newLF":{"cutPaper":false}},
  • {"htmlString":{"content":"<html><body><h1>HTML String</h1></body></html>", "cutPaper":false}},
  • {"newLF":{"cutPaper":false}},
  • {"htmlElementId":{"id":"receiptContent", "cutPaper":false}},
  • {"newLF":{"cutPaper":false}},
  • {"documentURL":{"url":"https://www.kioskproapp.com/api/print/star-print-raster-mode-receipt.html", "cutPaper":true}},
  • {"openCashDrawer":{"number":1}},
Example
kp_StarPrinter_startBatchPrinting({
	"printURL": {"url":"http://google.by", "cutPaper":true},
	"openCashDrawer": {"cashDrawerId":1}
});
		

Status

Function will return one of the following callbacks depending on the status of the operation:


kp_StarPrinter_printHTMLString

Added in 8.4

This function prints a string of HTML code with HTML formatting converted to basic printer markup.

Format
kp_StarPrinter_printHTMLString(htmlString,cutPaper);
		
Parameters
  • htmlString = string of HTML code that should be printed.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printDocumentAtURL

Added in 8.4

This function prints a document located at the specified URL or filepath.

Format
kp_StarPrinter_printDocumentAtURL(htmlUrl);
		
Parameters
  • htmlUrl = url or filepath to document to be printed.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printHtml

This function prints the content of the elementId parameter, including all its child elements, with HTML formatting converted to basic printer markup. Supported styles include:

  • bold = set by tag <b>...</b> or css property {font-weight:bold;}
  • underline = set by tag <u>...</u> or css property {test-decoration:underline;}
  • headings = set by tags <h1>...</h1> to <h6>...</h6>, which affect text size and weight
  • margin = set by css property, for example {margin-left:10px;} sets the text margin from the left side, measured in symbols
  • text alignment = set by css property, for example {text-align:left;} sets the text margin from the left side, measured in symbols

Images should have a width of 576px when printed on 3-inch printers, and a width of 832px when printed on 4-inch printers. PNG and JPG formats are supported, SVT is not supported.

We highly recommend testing images for contrast to make sure details aren't lost when printed in black and white.

Format
kp_StarPrinter_printHtml(elementId,cutPaper);
		
Parameters
  • elementId = id of root element to print as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printQRCode

This function prints defined text parameter as an equivalent QR code.

Format
kp_StarPrinter_printQRCode(codeText,cutPaper);
		
Parameters
  • codeText = text to print in QR code format as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printCode39

This function prints defined text parameter as an equivalent Code 39 style barcode.

Format
kp_StarPrinter_printCode39(codeText,cutPaper);
		
Parameters
  • codeText = text to print in code39 format as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printCode93

This function prints defined text parameter as an equivalent Code 93 style barcode.

Format
kp_StarPrinter_printCode93(codeText,cutPaper);
		
Parameters
  • codeText = text to print in code93 format as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_printCode128

This function prints defined text parameters as an equivalent Code 128 style barcode.

Format
kp_StarPrinter_printCode128(codeText,cutPaper);
		
Parameters
  • codeText = text to print in code128 format as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:


kp_StarPrinter_selectCodePage

Star Micronics printers support several character sets, which can be useful if you need to print characters or symbols not included in the ‘Windows Latin-1’ character set that Kiosk Pro uses by default. This function allows you to define another character set as needed.

You can view Star’s full character code table on our site here.

Format
kp_StarPrinter_selectCodePage(reference);
		
Parameters reference = reference number of the preferred character set, as string. The following character sets are supported (shown following the reference number used to identify that character set):
  • 0 = Normal
  • 1 = code page 437 (USA, Std. Europe)
  • 2 = Katakana
  • 3 = code page 437 (USA, Std. Europe)
  • 5 = code page 852 (Latin-2)
  • 6 = code page 869 (Portuguese)
  • 7 = code page 861 (Icelandic)
  • 8 = code page 863 (Canadian French)
  • 9 = code page 865 (Nordic)
  • 10 = code page 866 (Cyrillic Russian)
  • 11 = code page 855 (Cyrillic Bulgarian)
  • 12 = code page 857 (Turkey)
  • 13 = code page 862 (Israel, Hebrew)
  • 14 = code page 864 (Arabic)
  • 15 = code page 737 (Greek)
  • 16 = code page 851 (Greek)
  • 17 = code page 869 (Greek)
  • 21 = code page 874 (Thai)
  • 32 = code page 1252 (Windows Latin-1, default)
  • 33 = code page 1250 (Windows Latin-2)
  • 34 = code page 1251 (Windows Cyrillic)

Status

Nothing directly, however if Kiosk Pro isn’t able to convert the requested source text for printing to the Star Micronics printer using the current character set, the app will alert you as follows:

  • If printing was triggered through the use of the JavaScript API calls listed here, the app will return the callback kp_StarPrinter_printDidFailWithError(errorCode) with the error code -999.
  • If printing was triggered through the print icon in the Navigation Bar, an alert will be shown on-screen.


kp_StarPrinter_openCashDrawer

This function triggers an attached cash drawer to open.

Format
kp_StarPrinter_openCashDrawer(numberOfDrawer);
		
Parameters
  • numberOfDrawer = integer representing the number of the cash drawer to be opened.
    • 1 = primary cash drawer. This value should be used in the majority of use cases.
    • 2 = secondary cash drawer.

Status

Function will return one of the following callbacks depending on the status of the operation:


kp_StarPrinter_requestCashDrawerStatus

This function triggers a callback returning the current status of the cash drawer.

Format
kp_StarPrinter_requestCashDrawerStatus();
		

Status

Function will return one of the following callbacks depending on the status of the operation:


kp_StarPrinter_startListenToBarcodeScannerEvents

This function triggers the barcode scanner to start listening for a scan.

Format
kp_StarPrinter_startListenToBarcodeScannerEvents();
		

Status

Function will return one or more of the following callbacks depending on the status of the operation:


kp_StarPrinter_stopListenToBarcodeScannerEvents

This function triggers the barcode scanner to stop listening for a scan.

Format
kp_StarPrinter_stopListenToBarcodeScannerEvents();
		

Status

Function will return the following callback:


kp_StarPrinter_printDidFinish

This callback is triggered when printing has been successful.

Format
kp_StarPrinter_printDidFinish();
		


kp_StarPrinter_printDidFailWithError

This callback is called if the printing could not be performed for any reason or if an error occurred during printing.

Format
kp_StarPrinter_printDidFailWithError(errorCode);
		
Return values errorCode = code of error as integer. The following are possible:
  • -1001 = Star Micronics Printer is not enabled in Kiosk Pro settings.
  • -999 = returned if Kiosk Pro isn’t able to convert the requested source text for printing using the current character set.
  • 1 = Failure to open port.
  • 2 = Write port timed out.


kp_StarPrinter_statusOfPrinterDidChange

This callback is triggered before sending data to the printer, after printing, or as the result of kp_StarPrinter_requestStatusOfPrinter() being called.

Format
kp_StarPrinter_statusOfPrinterDidChange(typeOfStatus, isStatusError, beforePrinting);
		
Return values
  • typeOfStatus = type of status as integer. The following are returned:
    • 1 =Offline status.
    • 2 = Overflow status.
    • 3 = Cut status.
    • 4 = Out of Paper status.
    • 5 = Paper Jam status.
    • 6 = Paper Near status.
  • isStatusError = boolean. If 1 - then specified status is in the error state, otherwise - no.
  • beforePrinting = boolean. If 1 - then this callback is called before sending data to the printer, otherwise - after. If method is triggered as the callback of kp_StarPrinter_requestStatusOfPrinter value is equal to 0.


kp_StarPrinter_stateOfSupportingDidChange

This callback is triggered when user calls kp_StarPrinter_requestStateOfSupporting() and each time the user changes Kiosk Pro's settings.

Format
kp_StarPrinter_stateOfSupportingDidChange(supported);
		
Return values supported state as boolean:
  • 1 = if Star Micronics Printer is enabled in Kiosk Pro's settings.
  • 0 = if Star Micronics Printer is disabled in Kiosk Pro's settings.


kp_StarPrinter_statusOfCashDrawerDidChange

This callback is triggered when the current state of the cash drawer changes or when the user calls kp_StarPrinter_openCashDrawer or kp_StarPrinter_requestCashDrawerStatus.

Format
kp_StarPrinter_statusOfCashDrawerDidChange(isOnline, isOpened);
		
Return values
  • isOnline = integer indicating the current connection status of the cash drawer.
    • 1 = cash drawer is connected and correctly configured in Kiosk Pro settings.
    • 0 = app is unable to communicate with cash drawer.
  • isOpened = integer indicating whether the cash drawer is open.
    • 1 = cash drawer is currently open.
    • 0 = cash drawer is currently closed.


kp_StarPrinter_statusOfCashDrawerDidFailWithError

This callback is triggered when the cash drawer fails to respond following kp_StarPrinter_openCashDrawer or kp_StarPrinter_requestCashDrawerStatus.

Format
kp_StarPrinter_statusOfCashDrawerDidFailWithError(errorCode);
		
Return values errorCode = integer indicating the current error state of the cash drawer.
  • 0 = no error returned.
  • 1 = failure to open port.
  • 2 = command to port timed out.
  • 3 = cash drawer is offline.


kp_StarPrinter_batchPrintingDidFailWithError

Format
kp_StarPrinter_batchPrintingDidFailWithError(error);
		
Return values error = integer indicating the current error state of the cash drawer.
  • 0 = no error returned.
  • 1 = failure to open port.
  • 2 = command to port timed out.
  • 3 = cash drawer is offline.


kp_StarPrinter_batchPrintingDidFinishSuccessfully

This callback is triggered when printing has been successful.

Format
kp_StarPrinter_batchPrintingDidFinishSuccessfully();
		


kp_StarPrinter_barcodeScannerDidReceiveData

This callback is triggered when a barcode scan is successful.

Format
kp_StarPrinter_barcodeScannerDidReceiveData(data);
		
Return values data = interpreted data from the scan as a string.


kp_StarPrinter_barcodeScannerDidImpossible

This callback is triggered if the Star printer does not support the barcode scanner.

Format
kp_StarPrinter_barcodeScannerDidImpossible();
		


kp_StarPrinter_barcodeScannerDidImpossible

This callback is triggered if the Star printer does not support the barcode scanner.

Format
kp_StarPrinter_barcodeScannerDidImpossible();
		


kp_StarPrinter_barcodeScannerDidConnect

This callback is triggered when the barcode scanner is connected and/or after kp_StarPrinter_startListenToBarcodeScannerEvents is called while the scanner is connected.

Format
kp_StarPrinter_barcodeScannerDidConnect();
		


kp_StarPrinter_barcodeScannerDidDisconnect

This callback is triggered when the barcode scanner is disconnected and/or after kp_StarPrinter_startListenToBarcodeScannerEvents is called while the scanner is disconnected.

Format
kp_StarPrinter_barcodeScannerDidDisconnect();
		


kp_StarPrinter_barcodeScannerDidImpossible

This callback is triggered if the Star printer does not support the barcode scanner.

Format
kp_StarPrinter_barcodeScannerDidImpossible();
		


kp_StarPrinter_printText

This function prints the text parameter defined as simple text.

Format
kp_StarPrinter_printText(codeText,cutPaper);
		
Parameters
  • codeText = text to print as a string.
  • cutPaper = integer. Use of this parameter requires the Cut Paper setting to be set to JavaScript Call.
    • 1 = printer will perform a cut immediately after print job finishes.
    • 0 = printer will not perform a cut.

Status

Function will return one of the following callbacks depending on the status of the print job:

Still stuck? How can we help? How can we help?