This plugin enables you to use the CaptureID Printer Library and to easily integrate Bluetooth printing into your app(s).
new:
new:
new:
discoverDevices(options: {timeout: number});
connecteddevice now contains vendor name and printer model
enums and methods to extract vendor and model from result.
fixed:
new:
getPrinterInformation(): Promise<CIDPrinterInformation>;
new:
enableClipping(options: {enable: boolean}): void;
enable/disable clipping (prevents Honeywell/Intermec printer from displaying "Field out of Label" messages)
new:
enableBluetoothAdapter(options {enable: boolean}): Promise<PrinterLibraryEvent>;
enableCalibration(options: {enable: boolean}): void
getMediaSize(): Promise<MediaSize>;
isBluetoothAdapterEnabled(): Promise<{result: boolean}>;
sendFormFeed(): void;
The CaptureID Printer plugin expires after a 3 month evaluation period. After this period you must request a valid license key. This license must be purchased separatly and is not included in this package. For additional Information of the CaptureID Licensing and how to get access to a valid license Key visit our Website under (https://www.captureid.de).
The CaptureID Printer Plugin can be used in Ionic Capacitor app's to support label printing on SATO mobile Printers (i.e. MB200i, PW208nx), SATO Desktop Printers (i.e. CT4LX), Honeywell Printers that supports Fingerprint Language and a wide range of ZEBRA Printers (mobile and Desktop Models). It enables you to easily scan for Bluetooth Printers, connect to an selected printer or the last connected printer.
Install the plugin into your existing project by running the command
npm install @captureid/capacitor3-cidprint@latest
run the build command to integrate the plugin code and it's libraries into your android project and to open the project in Android Studio
ionic capacitor run android
Note: In case of an error during the build process stating cidprintlibrary and/or supportv1 can't be found you have to add the following entry into your apps build.gradle file to ensure the required files can be found.
repositories { mavenLocal() maven { url("$rootDir/../node_modules/@captureid/capacitor3-cidprint/android") } }
With the CaptureID Printer plugin installed and configured, the only thing left is to add the necessary code to your app.
-
Call the provided functions and add the callbacks.
-
Call initCIDPrinterLib to initialize the Library. This method returns a PrinterLibraryEvent as result. If the initialization of the PrinterLibrary is successful and the required Permissions are granted the fields of the PrinterLibraryEvent structure are set with the values In case of the app is missing some permissions the EventType of the struct is set to NOTIFY and the data field is a type of InitResult class, which contains the required permissions in an array of strings.
-
Register the LibraryListener with addListener(CIDPrinterListenerTypes.PRINTER_LIBRARY, (event: PrinterLibraryEvent) => {}). The Listener Method receives all event fired by the PrinterLibrary.
-
The method "discoverDevices" calls the Discover Listener, You can register the listener by adding the Listener Callback method with the Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => { let data: PrinterEvent = result.result[0];}); command
-
the result contains Result Type of PrinterEvent. The PrinterEvent structure consist of the following fields:
- type: PrinterEventType;
- status: PrinterStatusType;
- message: string;
- error: number;
- device: Device;
- devices: Device[];
- action: PrinterActionType;
- initCIDPrinterLib(): Promise<{event: PrinterLibraryEvent}>;
- closeCIDPrinterLib(): void;
- activateLicense(options: { productKey: string; }): void;
- enableBluetoothPrinting(options: { enable: boolean; }): void;
- getPairedDevices(): Promise<{}>;
- discoverDevices(): void;
- connectToPreferredPrinter(options: { mac: string; }): void;
- printData(options: { data: string; }): void;
- printLabelWithData(options: { label: string; data: string[]; }): void;
- printLabel(options: { label: string; }): void;
activateLicense(options: { licenseKey: string; customerID: string; }) => Promise<PrinterLibraryEvent>
Param | Type |
---|---|
options |
{ licenseKey: string; customerID: string; } |
Returns: Promise<PrinterLibraryEvent>
closeCIDPrinterLib() => void
connectToPreferredPrinter(options: { mac: string; }) => void
Param | Type |
---|---|
options |
{ mac: string; } |
connectToPreferredPrinter(options: { mac: string; autoreconnect: boolean; timeout: number; }) => void
Param | Type |
---|---|
options |
{ mac: string; autoreconnect: boolean; timeout: number; } |
connectToPrinter(options: { address: string; }) => void
Param | Type |
---|---|
options |
{ address: string; } |
connectToPrinter(options: { address: string; autoreconnect: boolean; timeout: number; }) => void
Param | Type |
---|---|
options |
{ address: string; autoreconnect: boolean; timeout: number; } |
connectToPrinter(options: { address: string; port: number; }) => void
Param | Type |
---|---|
options |
{ address: string; port: number; } |
convert(options: { label: string; }) => void
Param | Type |
---|---|
options |
{ label: string; } |
disconnectFromPrinter(options: { mac: string; }) => void
Param | Type |
---|---|
options |
{ mac: string; } |
discoverDevices(options: { timeout: number; }) => void
Param | Type |
---|---|
options |
{ timeout: number; } |
enableBluetoothAdapter(options: { enable: boolean; }) => Promise<PrinterLibraryEvent>
Param | Type |
---|---|
options |
{ enable: boolean; } |
Returns: Promise<PrinterLibraryEvent>
enableBluetoothPrinting(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
enableCalibration(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
enableClipping(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
enableDebugToFile(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
enableDispendingMode(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
enableNetworkPrinting(options: { enable: boolean; }) => void
Param | Type |
---|---|
options |
{ enable: boolean; } |
getLatestConnectState() => Promise<PrinterLibraryEvent>
Returns: Promise<PrinterLibraryEvent>
getMediaSize() => Promise<MediaSize>
Returns: Promise<MediaSize>
getPairedDevices() => void
getPrinterInformation() => Promise<CIDPrinterInformation>
Returns: Promise<CIDPrinterInformation>
getPrinterLibraryVersion() => Promise<string>
Returns: Promise<string>
getPrinterStatus() => void
initCIDPrinterLib() => Promise<PrinterLibraryEvent>
Returns: Promise<PrinterLibraryEvent>
isBluetoothAdapterEnabled() => Promise<{ result: boolean; }>
Returns: Promise<{ result: boolean; }>
isLibraryInitialized() => Promise<{ result: boolean; }>
Returns: Promise<{ result: boolean; }>
printData(options: { data: string; }) => void
Param | Type |
---|---|
options |
{ data: string; } |
printLabel(options: { label: string; }) => void
Param | Type |
---|---|
options |
{ label: string; } |
printLabelWithData(options: { label: string; data: string[]; }) => void
Param | Type |
---|---|
options |
{ label: string; data: string[]; } |
printLabelWithObject(options: { label: string; data: TicketData; }) => void
Param | Type |
---|---|
options |
{ label: string; data: TicketData; } |
printNativeData(options: { data: string; }) => void
Param | Type |
---|---|
options |
{ data: string; } |
printReferenceLabel(options: { labeltype: ReferenceTicketType; }) => void
Param | Type |
---|---|
options |
{ labeltype: ReferenceTicketType; } |
requestPermission(options: { permission: string; }) => Promise<{ result: boolean; }>
Param | Type |
---|---|
options |
{ permission: string; } |
Returns: Promise<{ result: boolean; }>
requestAllPermissions(options: { permissions: string[]; }) => Promise<{ result: boolean; }>
Param | Type |
---|---|
options |
{ permissions: string[]; } |
Returns: Promise<{ result: boolean; }>
sendFormFeed() => void
setAutoReconnect(options: { autoreconnect: boolean; }) => void
Param | Type |
---|---|
options |
{ autoreconnect: boolean; } |
setConfiguration(options: { config: PrinterConfiguration; }) => void
Param | Type |
---|---|
options |
{ config: PrinterConfiguration; } |
setTimeouts(options: { gap: number; timeout: number; status: number; information: number; formfeed: number; detect: number; }) => void
Param | Type |
---|---|
options |
{ gap: number; timeout: number; status: number; information: number; formfeed: number; detect: number; } |
setupMediaSize(options: { width: number; height: number; }) => void
Param | Type |
---|---|
options |
{ width: number; height: number; } |
showNavigationBar(options: { show: boolean; }) => void
Param | Type |
---|---|
options |
{ show: boolean; } |
showSettings(options: { show: boolean; }) => void
Param | Type |
---|---|
options |
{ show: boolean; } |
showUI(options: { show: boolean; }) => void
Param | Type |
---|---|
options |
{ show: boolean; } |
uploadFile(options: { file: string; filetype: number; }) => void
Param | Type |
---|---|
options |
{ file: string; filetype: number; } |
addListener(eventName: string, listenerFunc: (data: PrinterLibraryEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Param | Type |
---|---|
eventName |
string |
listenerFunc |
(data: PrinterLibraryEvent) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
removeAllListeners() => void
Prop | Type |
---|---|
sender |
string |
type |
EventType |
message |
string |
error |
number |
data |
ResultClass |
action |
PrinterLibraryActionType |
Prop | Type |
---|---|
width |
number |
height |
number |
Prop | Type |
---|---|
firmware |
Firmware |
main_firmware |
Firmware |
module_firmware |
Firmware |
sensor_boot_firmware |
Firmware |
sensor_firmware |
Firmware |
media |
Media |
battery |
Battery |
modeltype |
number |
modelname |
string |
dpi |
number |
dots_mm |
number |
dots |
number |
lanaddress |
string |
wlanaddress |
string |
btaddress |
string |
headcount |
string |
lifecount |
string |
cutcount |
string |
dispensecount |
string |
thermotransfer |
boolean |
Prop | Type |
---|---|
version |
string |
date |
string |
checksum |
string |
Prop | Type |
---|---|
labelwidth |
number |
labelheight |
number |
Prop | Type |
---|---|
cyclecount |
number |
chargestat |
number |
health |
number |
remain |
number |
Prop | Type |
---|---|
variables |
TicketVariable |
Prop | Type |
---|---|
disconnectonpause |
boolean |
connectonresume |
boolean |
lowbatterythreshold |
number |
media |
CIDMedia |
Prop | Type |
---|---|
size |
MediaSize |
type |
MediaType |
Prop | Type |
---|---|
remove |
() => Promise<void> |
Members | Value |
---|---|
SUCCESS |
0 |
NOTIFY |
1 |
FAILED |
2 |
Members | Value |
---|---|
NONE |
0 |
INITIALIZE |
1 |
BLUETOOTH_INITIALIZE |
2 |
BLUETOOTH_ENABLE |
3 |
BLUETOOTH_DISABLE |
4 |
DISCOVER_START |
5 |
DISCOVER_DETECT |
6 |
DISCOVER_FINISH |
7 |
CONNECT |
8 |
DISCONNECT |
9 |
PRINT |
10 |
STATUS |
11 |
CONFIGURE |
12 |
BLUETOOTH_TURNED_OFF |
13 |
BLUETOOTH_TURNED_ON |
14 |
LICENSE_ACTIVATION |
15 |
FILEUPLOAD |
16 |
EXCEPTION |
17 |
Members | Value |
---|---|
DOT_MATRIX |
0 |
Members | Value |
---|---|
GAP |
0 |
IMARK |
1 |
await initCIDPrinterLib();
Version 0.1.0 Parameters: - none
await closeCIDPrinterLib();
Version 0.1.0 Parameters: - none
await activateLicense(key: string, customer: string);
Version 0.1.0 Parameters:
- key (string) - valid Licensekey.
- customer (string) - valid CustomerId.
await enableBluetoothPrinting(enable: boolean);
Version 1.0.0 Parameters:
- enable (boolean) - Enables/disables the Printing via Bluetooth.
getPairedDevices();
Version 0.1.0
Parameters:- none
discoverDevices();
Version 0.1.0
Parameters:- none
printData(data: string);
Version 0.1.0
Parameters:
- data (string) - data to be printed.
printLabelWithData(label: string, data: string[]);
Version 0.1.0
Parameters:
- label: path and filename of the label template file relative to the android project assets folder.
- data[]: array of strings representing a value for each placeholder (count and length of the array and the contained strings must match the variables in the label template)
printLabel(label: String);
Version 0.1.0
Parameters:
- label: path and filename of the label template file relative to the android project assets folder.
connectToPreferredPrinter(mac: string);
Version 0.1.0
Parameters:
- mac: Bluetooth Mac Address of the printer to connect or an empty string. If an empty string is provided a connection to the last connected printer is established.
let event: PrinterLibraryEvent = await CIDPrint.initCIDPrinterLib();
if(event.type === EventType.NOTIFY) {
if(event.action === PrinterLibraryActionType.INITIALIZE) {
let data: InitResult = event.data as InitResult;
for(let i = 0; i < data.permissions.length; i++) {
// list the required permissions.
}
}
}
For the sample code to work it is required to call initCIDPrinter and enableBlutoothPrinting.
Register the callback method for the discover procedure
discoverListener = Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => {
let data: PrinterEvent = result.result[0];
if(data.action === PrinterActionType.LIST_PRINTER) {
this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
} else if(data.action === PrinterActionType.LIST_PRINTERS) {
this.setState({ devices: data.devices });
}
});
discover() {
CIDPrint.discoverDevices();
}
call discover to start the Blutooth Discover procedure.
if a mobile SATO Bluetooth printer is detected the listener is invoked with a PrinterActionType of LIST_PRINTER and the Printers Mac Address and Device Name in the device field of the PrinterEvent Structure.
On finish Discover process the callback method is invoked with a LIST_PRINTERS PrinterActionType and a list of all dicovered SATO Printers is available in the devices field of the PrinterEvent Structure.
complete source code
import { IonButton, IonContent, IonHeader, IonItem, IonList, IonPage, IonText, IonTitle, IonToolbar } from '@ionic/react';
import { Plugins } from '@capacitor/core';
import React, { Component } from 'react';
import ExploreContainer from '../components/ExploreContainer';
import './Home.css';
import 'capacitor-cidprint';
import { Device, ListenerTypes, PrinterActionType, PrinterEvent } from 'capacitor-cidprint';
import { useLocation } from 'react-router';
import { convertCompilerOptionsFromJson } from 'typescript';
const { CIDPrint } = Plugins;
export class Home extends Component {
state = {
enabled: false,
connected: false,
devname: '',
devmac: '',
devices: Array<Device>()
}
constructor(props: any) {
super(props);
this.state = { enabled: false, connected: false, devname: '', devmac: '', devices: [] };
}
discoverListener = Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => {
let data: PrinterEvent = result.result[0];
if(data.action === PrinterActionType.LIST_PRINTER) {
this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
} else if(data.action === PrinterActionType.LIST_PRINTERS) {
this.setState({ devices: data.devices });
}
});
printListener = Plugins.CIDPrint.addListener(ListenerTypes.PRINT, (result: any) => {
let data: PrinterEvent = result.result[0];
if(data.action === PrinterActionType.LIST_PRINTER) {
this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
} else if(data.action === PrinterActionType.LIST_PRINTERS) {
if(data.devices.length > 0) {
this.setState({ devmac: data.devices[0].devicemac, devname: data.devices[0].devicename });
}
}
});
async init() {
await CIDPrint.initCIDPrinterLib();
}
async enableBluetooth() {
this.setState({ enabled: await CIDPrint.enableBluetoothPrinting({enable: true})})
}
discover() {
CIDPrint.discoverDevices();
}
async connect(printer: Device) {
this.setState({connected: await CIDPrint.connectToPreferredPrinter({mac: printer.devicemac })})
}
async print(label: String, data: String[]) {
console.log('vorher');
await CIDPrint.printLabel({label: 'label41.dat'})
console.log('nachher');
}
render() {
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>Bluetooth Print</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
<IonButton onClick={() => this.init()}>Initialize Plugin</IonButton>
<IonButton onClick={() => this.enableBluetooth()}>Enable Bluetooth</IonButton>
<IonButton disabled={!this.state.enabled} onClick={() => this.discover()}>Discover Bluetooth Printer</IonButton>
<IonButton disabled={!this.state.connected} onClick={() => this.print('', ['', ''])}>Print Label</IonButton>
<IonList>
{this.state.devices.map((item) => (
<IonItem onClick={() => this.connect(item)}><IonText>{ item.devicename } -- { item.devicemac }</IonText></IonItem>
))}
</IonList>
</IonContent>
</IonPage>
);
}
}
export default Home;