The Brady Web SDK API
All API methods below are members of the BradySdk class. This is the only class in the SDK that should be used.
BradySdk (constructor)
new BradySdk(callback: function, collectAnalytics?: bool)
The constructor of the BradySdk class should be initialized immediately when the user's web page has loaded. All functionality depends on this single object.
-
A function must be passed into this constructor that will trigger whenever there is an update in the back-end's BradySdk view model. A user can simply update the UI accordingly whenever this method is triggered. An example can be seen in the "printerUpdatesCallback" method used in the example on https://sdk.bradyid.com/web_sdk_setup/.
-
Additionally, the BradySdk class accepts an optional boolean argument. If no value is passed in, analytics related to print jobs will be collected by default to assist Brady developers in continuing to improve the SDK. If 'false' is passed in, no analytics will be collected. Passing in 'true' is redundant since analytics are collected by default.
.showDiscoveredBleDevices
async showDiscoveredBleDevices(string): string
showDiscoveredBleDevices opens the embedded Bluetooth discovery window that comes with the Web Bluetooth API. If a user selects a device in this window and clicks the "pair" button, it will attempt to connect to the device.
- Takes a string that represents the ID that should be used to gain ownership of an M211. When using an M611, null can be used.
- If the connection fails or the user clicks outside of the pop-up window before the connection is finished, this method will return null.
- If the connection is successful, this method will return a unique ID that can be used in the future to reconnect to the same device.
NOTE: The Web SDK test app saves the returned ID in localStorage in order to connect to an M211/M610 across separate refreshes of web pages. This ID is required by the M211/M610 if the Bluetooth light on the printer is solid blue. If this ID is not saved, the power button can be held for 5 seconds to release ownership before every connection on the M211 or manually forgotten on the M610.
.isConnected
isConnected(): boolean
isConnected will return a boolean representing if any device is connected to the Web SDK at the time of its call.
.isSupportedBrowser
isSupportedBrowser(): boolean
isSupportedBrowser indicates whether the browser being used to run your app is supported by the Web Bluetooth API. Example browsers that support the API include Google Chrome, Microsoft Edge, and Bluefy (on iOS).
- Returns a boolean representing whether the browser running your app is supported by the Web Bluetooth API.
.feed
async feed(): boolean
feed is only functional when connected to an M211 or M511. This will tell the printer to print exactly one blank label.
- Returns a boolean representing the success of the operation.
.cut
async cut(): boolean
cut is only functional when connected to an M211 or M511. This will tell the printer to perform a cut operation.
- Returns a boolean representing the success of the operation.
.printBitmap
async printBitmap(bitmap, xOffset = 0, yOffset = 0): boolean
printBitmap prints the HTML img tag that it's handed. The image always maintains its aspect ratio and will be resized to fill the dimension of the first printable zone of the installed supply in the connected printer. The parameters "xOffset" and "yOffset" are optional values to manually shift the image on the printed out label (in inches). These parameters will default to 0. It is encouraged to only used these optional parameters if the printed out label does not meet your standards.
For users that have difficulties passing in an img object, refer to the code block titled "CODE TO SELECT AND DISPLAY IMAGE TO PRINT" in the example at: https://sdk.bradyid.com/web_sdk_setup/.
- Returns a boolean representing the success of the print operation. This will return false if there is no printer connected.
.disconnect
async disconnect(): boolean
disconnect severs the current connection to the Bluetooth GATT. This will also clear the "ownershipID" field in localStorage.
- Returns a boolean representing the success of the disconnection.
.setCopies
setCopies(number): void
setCopies allows you to specify the number of copies of the image you want to print. The default number of copies for each print job is 1.
.setCutOption
setCutOption(number): void
setCutOption allows you to specify the cut option for your print job.
EndOfJob = 0 - the printer will only cut at the end of the print job (default cut option)
EndOfLabel = 1 - if your print job consists of multiple copies, this will cut in between each copy
Never = 2 - the printer will never cut your printed label and must be done manually
CutAfterRow = 3 - the printer will cut your printed label only after the amount of rows specified
UsePrinterSettings = 4 - the printer will resort to using the cut option set on the printer
.setCutAfterRowValue
setCutAfterRowValue(cutAfterRowValue: number): void
setCutAfterRowValue allows you to specify how many labels to print before a cut action is performed. For example, "setCutAfterRowValue(2)" will tell the printer to cut after every 2 labels. This option is only supported on the M611, S3700, and i7500. Print will not be successful when used with an unsupported printer.
.setSupplyDatabase
setSupplyDatabase(supplyDatabaseFile: File) : void
supplyDatabaseFile allows you to specify a new Supply Database file to override the embedded one. This may be used in cases where the printed out image is not fully on the printable area of the label or if the image is sized incorrectly.
.parsePdfToImages
parsePdfToImages(file: File) : HTMLImageElement[]
file a file object of a PDF file.
- Returns an array of HTMLImageElements whose items represent each page of the PDF file as an image that will print on its own label.
Printer Properties of BradySdk
All instance variables will be null of undefined until a successful connection to a printer has been made. Not all properties of BradySdk apply to every printer model and may still be undefined after connection. We have tried to specify all these cases below.
- status: the current status of the connected printer.
- printerName: the name of the connected printer.
- printerModel: the model of the connected printer
- supplyName: the name of the connected printer's supply part.
- supplyDimensions: the width and height of the installed part in inches
- supplyRemainingPercentage: the percentage remaining of the connected printer's supply.
- supplyIsDirectThermal: Is the supply installed in the connected printer direct thermal or not.
- postPrintAccessoryType: The hardware accessory installed on the printer for post-printing actions (i7500 only).
- dotsPerInch: The dots per inch capabilities of the connected printer.
- substrateYNumber: the Y Number of the current part installed in the connected printer.
- substrateWidth: the width of the current supply installed in the connected printer.
- substrateHeight: the height of the current supply installed in the connected printer.
- mediaIsDieCut: indicates whether the installed supply is die-cut or continuous.
- rotation: where on the label your image will be printed
- orientation: the orientation of the part (Landscape or Portrait)
- leftOffset: the horizontal offset of the installed supply to help center the image being printed
- verticalOffset: the vertical offset of the installed supply to help center the image being printed
- zoneDimensions: the width and height of the first printable zone on the installed part; this is necessary to have as installed parts can have a number of printable zones that may differ from the default width and height
- batteryLevelPercentage: the percentage of battery left in the connected printer.
- isAcConnected: if the connected printer is plugged into an AC power source.
- firmwareVersion: the firmware version number of the connected printer.
- autoShutoffTimeInMinutes: the time in minutes that it takes the connected printer to shut off automatically (M211 & M511 only).
- message: the message body of a printer error.
- messageTitle: the message title of a printer error.
- messageRemedy: the remedy explanation of a printer error.
- printOptions: object containing the values for cutOption, copies, and collate (only applicable for M511 print jobs)
- mostRecentUpdates: a list of variables that may have been changed (for example, if you changed the part in your printer or if the battery level percentage of your printer has changed); passed in as an argument to printerUpdatesCallback
- isSupplyValid: the validity of the installed supply in the connected printer
- isRibbonValid: the validity of the installed ribbon in the connected printer
- labelLibraryVersion: the version number of the YB file installed on the connected printer's firmware (all printers except the M211 & M511).
- errorSeverity: if there is a current error on the connected printer, this will represent the severity level of the error (example: Error, Warning, Info, etc.)
- supplyIsPreprinted: if there is a preprinted graphic on the label