Printing:
-
To print, call
printerDetails.print(context, template, printingOptions, dontPrintTrailerFlag)
context
is the UI Context object.template
is the Template object (reference the Open Templates page).printingOptions
is the PrintOptions object we initialize (reference below).dontPrintTrailerFlag
is a Boolean that represents if we want a trailer on our label.
-
The SDKs PrintingOptions is used to set CutOptions and the number of copies to print.
PrintingOptions printingOptions = new PrintingOptions(); printingOptions.setCutOption(CutOption.EndOfJob); printingOptions.setNumberOfCopies(1);
-
Similar to connecting, it is recommended to call the .print() method inside another thread.
- A progress bar can be used similar to when we connected to the printer.
- All together, a UI's print function may look like:
public void printTemplate(Template template) {
PrintingOptions printingOptions = new PrintingOptions();
printingOptions.setCutOption(CutOption.EndOfJob);
printingOptions.setNumberOfCopies(1);
printingOptions.setIsCollated(true);
Runnable r = () -> {
runOnUiThread(()->progressBar.setVisibility(View.VISIBLE));
printerDetails.print(context, template, printingOptions, null);
runOnUiThread(()->progressBar.setVisibility(View.INVISIBLE));
};
Thread printThread = new Thread(r);
printThread.start();
}
- Alternatively, if the desire is to simply print an image instead of a Brady Workstation template, you may use the print method shown below.
public void print(Bitmap bitmap) {
PrintingOptions printingOptions = new PrintingOptions();
printingOptions.setCutOption(CutOption.EndOfJob);
printingOptions.setNumberOfCopies(1);
Runnable r = () -> {
runOnUiThread(()->progressBar.setVisibility(View.VISIBLE));
printerDetails.print(context, bitmap, printingOptions, false);
runOnUiThread(()->progressBar.setVisibility(View.INVISIBLE));
};
Thread printThread = new Thread(r);
printThread.start();
}
- Use extensions such as PNGs, JPGs, JPEGs, WEBPs, or SVGs can be converted into a Bitmap. For example, "selectedFileName" was a file named "bradylogo.png" that the user selected:
String selectedFileName = templatesSpinner.getSelectedItem().toString();
InputStream iStream = getResources().openRawResource(getResources().getIdentifier(selectedFileName.split("[.]")[0], "raw", getPackageName()));
bitmap = BitmapFactory.decodeStream(iStream);