[![appcenterbanner](https://www.captureid.de/wp-content/uploads/2020/12/captureid_logo-1.svg)](https://www.captureid.de/)

# Ionic Capacitor 5 Plugin for Mobile Print

This plugin enables you to use the CaptureID Printer Library and to easily integrate Bluetooth printing into your app(s).


## Release Notes

### version 5.0.54

new:
    ### setTimeouts interface changed

### version 5.0.52

doc added:
    ### description of timeout variables

### version 5.0.48

fixed:
    ### print doubles when stressing printer in batch printing mode

### version 5.0.46

new:
    ### broadcastreceiver visibility/accessibility changed for Android 14

### version 5.0.40

fixed:
    ### disconnect call on error in connection process.

### version 5.0.38

new:
    ### new method setLTSSensitivity added. Single number Parameter required - value betwenn 0 to 15. This Method is only available on PC23D printer

### version 5.0.36

fixed:
    ### LTS handling using PC23D with multiple tickets.

### version 5.0.35

fixed:
    ### App crashes while connecting to PC23D first time.

### version 5.0.34

fixed:
    ### PC23d printer timeouts while printing multiple tickets (i.e. 50 pcs).

new:
    ### quantity parameter added to printLabelWithObject

### version 5.0.33

    ### timout adjusted for bixolon printer reconnect

### version 5.0.32

fixed:
    ### setupMediaSize return correct values on Bixolon printer
    ### printer no longer uses FNC codes when mac address should print

### version 5.0.29

fixed:
    ### memory leak in SATO support library
    ### Bixolon support added
    ### code128 barcode width calculation adjustment (centered barcodes)
    ### url in QRCode is now correctly displayed

### version 5.0.1

new:

#### switch to capacitor 5


### version 0.0.94

new:

#### Device class changed vendorname and printermodel to optional values

#### Font change for SATO MB200i

#### character spacing for PW208NX removed

  
### version 0.0.93

new:

```typescript
  discoverDevices(options: {timeout: number});
```

#### timout parameter added to discover method

#### connect result':'

  connecteddevice now contains vendor name and printer model

  enums and methods to extract vendor and model from result.

### version 0.0.92

fixed:

#### setupMediaSize does not return result for SATO printers

### version 0.0.91

new:

```typescript
  getPrinterInformation(): Promise<CIDPrinterInformation>;
```

#### retrieve detailed information of the printer

---

### version 0.0.90

new:

```typescript
  enableClipping(options: {enable: boolean}): void;
```

#### enable/disable clipping (prevents Honeywell/Intermec printer from displaying "Field out of Label" messages)

---

### version 0.0.89
  
  new:
  
  ```typescript
  enableBluetoothAdapter(options {enable: boolean}): Promise<PrinterLibraryEvent>;
  ```

#### enable/disable Bluetooth adapter

  ---

  ```typescript  
  enableCalibration(options: {enable: boolean}): void
  ```

#### trigger sensor calibration (Honeywell/Intermec printers)

  ---

  ```typescript
  getMediaSize(): Promise<MediaSize>;
  ```

#### request the media size currently set

  ---
  isBluetoothAdapterEnabled(): Promise<{result: boolean}>;

#### check if bluetoothadapter is enabled

  ---
  sendFormFeed(): void;

#### send a Formfeed request to the printer

  ---


<!-- Capacitor Catalog -->

* [Requirements](#requirements)
* [How does it work?](#how-does-it-work)
* [Getting Started](#getting-started)
* [Plugin Usage](#plugin-usage)
* [API Reference](#api-reference)
* [Sample Code](#sample-code)

<!-- Capacitor Catalog -->

## Requirements

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](https://www.captureid.de)). 

## How does it work?

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.

## Getting Started

Install the plugin into your existing project by running the command

```shell
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

```javascript
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")
    }
}

## Plugin Usage

With the CaptureID Printer plugin installed and configured, the only thing left is to add the necessary code to your app.

1. Call the provided functions and add the callbacks.

2. 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.

3. Register the LibraryListener with addListener(CIDPrinterListenerTypes.PRINTER_LIBRARY, (event: PrinterLibraryEvent) => {}). The Listener Method receives all event fired by the PrinterLibrary.
   
4. 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
5. 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;

## API Reference

- __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;

#

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### activateLicense(...)

```typescript
activateLicense(options: { licenseKey: string; customerID: string; }) => Promise<PrinterLibraryEvent>
```

| Param         | Type                                                     |
| ------------- | -------------------------------------------------------- |
| **`options`** | <code>{ licenseKey: string; customerID: string; }</code> |

**Returns:** <code>Promise&lt;<a href="#printerlibraryevent">PrinterLibraryEvent</a>&gt;</code>

--------------------


### closeCIDPrinterLib()

```typescript
closeCIDPrinterLib() => void
```

--------------------


### connectToPreferredPrinter(...)

```typescript
connectToPreferredPrinter(options: { mac: string; }) => void
```

| Param         | Type                          |
| ------------- | ----------------------------- |
| **`options`** | <code>{ mac: string; }</code> |

--------------------


### connectToPreferredPrinter(...)

```typescript
connectToPreferredPrinter(options: { mac: string; autoreconnect: boolean; timeout: number; }) => void
```

| Param         | Type                                                                   |
| ------------- | ---------------------------------------------------------------------- |
| **`options`** | <code>{ mac: string; autoreconnect: boolean; timeout: number; }</code> |

--------------------


### connectToPrinter(...)

```typescript
connectToPrinter(options: { address: string; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ address: string; }</code> |

--------------------


### connectToPrinter(...)

```typescript
connectToPrinter(options: { address: string; autoreconnect: boolean; timeout: number; }) => void
```

| Param         | Type                                                                       |
| ------------- | -------------------------------------------------------------------------- |
| **`options`** | <code>{ address: string; autoreconnect: boolean; timeout: number; }</code> |

--------------------


### connectToPrinter(...)

```typescript
connectToPrinter(options: { address: string; port: number; }) => void
```

| Param         | Type                                            |
| ------------- | ----------------------------------------------- |
| **`options`** | <code>{ address: string; port: number; }</code> |

--------------------


### convert(...)

```typescript
convert(options: { label: string; }) => void
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ label: string; }</code> |

--------------------


### disconnectFromPrinter(...)

```typescript
disconnectFromPrinter(options: { mac: string; }) => void
```

| Param         | Type                          |
| ------------- | ----------------------------- |
| **`options`** | <code>{ mac: string; }</code> |

--------------------


### discoverDevices(...)

```typescript
discoverDevices(options: { timeout: number; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ timeout: number; }</code> |

--------------------


### enableBluetoothAdapter(...)

```typescript
enableBluetoothAdapter(options: { enable: boolean; }) => Promise<PrinterLibraryEvent>
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

**Returns:** <code>Promise&lt;<a href="#printerlibraryevent">PrinterLibraryEvent</a>&gt;</code>

--------------------


### enableBluetoothPrinting(...)

```typescript
enableBluetoothPrinting(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### enableCalibration(...)

```typescript
enableCalibration(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### enableClipping(...)

```typescript
enableClipping(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### enableDebugToFile(...)

```typescript
enableDebugToFile(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### enableDispendingMode(...)

```typescript
enableDispendingMode(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### enableNetworkPrinting(...)

```typescript
enableNetworkPrinting(options: { enable: boolean; }) => void
```

| Param         | Type                              |
| ------------- | --------------------------------- |
| **`options`** | <code>{ enable: boolean; }</code> |

--------------------


### getLatestConnectState()

```typescript
getLatestConnectState() => Promise<PrinterLibraryEvent>
```

**Returns:** <code>Promise&lt;<a href="#printerlibraryevent">PrinterLibraryEvent</a>&gt;</code>

--------------------


### getMediaSize()

```typescript
getMediaSize() => Promise<MediaSize>
```

**Returns:** <code>Promise&lt;<a href="#mediasize">MediaSize</a>&gt;</code>

--------------------


### getPairedDevices()

```typescript
getPairedDevices() => void
```

--------------------


### getPrinterInformation()

```typescript
getPrinterInformation() => Promise<CIDPrinterInformation>
```

**Returns:** <code>Promise&lt;<a href="#cidprinterinformation">CIDPrinterInformation</a>&gt;</code>

--------------------


### getPrinterLibraryVersion()

```typescript
getPrinterLibraryVersion() => Promise<string>
```

**Returns:** <code>Promise&lt;string&gt;</code>

--------------------


### getPrinterStatus()

```typescript
getPrinterStatus() => void
```

--------------------


### initCIDPrinterLib()

```typescript
initCIDPrinterLib() => Promise<PrinterLibraryEvent>
```

**Returns:** <code>Promise&lt;<a href="#printerlibraryevent">PrinterLibraryEvent</a>&gt;</code>

--------------------


### isBluetoothAdapterEnabled()

```typescript
isBluetoothAdapterEnabled() => Promise<{ result: boolean; }>
```

**Returns:** <code>Promise&lt;{ result: boolean; }&gt;</code>

--------------------


### isLibraryInitialized()

```typescript
isLibraryInitialized() => Promise<{ result: boolean; }>
```

**Returns:** <code>Promise&lt;{ result: boolean; }&gt;</code>

--------------------


### printData(...)

```typescript
printData(options: { data: string; }) => void
```

| Param         | Type                           |
| ------------- | ------------------------------ |
| **`options`** | <code>{ data: string; }</code> |

--------------------


### printLabel(...)

```typescript
printLabel(options: { label: string; }) => void
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ label: string; }</code> |

--------------------


### printLabelWithData(...)

```typescript
printLabelWithData(options: { label: string; data: string[]; }) => void
```

| Param         | Type                                            |
| ------------- | ----------------------------------------------- |
| **`options`** | <code>{ label: string; data: string[]; }</code> |

--------------------


### printLabelWithObject(...)

```typescript
printLabelWithObject(options: { label: string; data: TicketData; quantity: number; }) => void
```

| Param         | Type                                                                                          |
| ------------- | --------------------------------------------------------------------------------------------- |
| **`options`** | <code>{ label: string; data: <a href="#ticketdata">TicketData</a>; quantity: number; }</code> |

--------------------


### printNativeData(...)

```typescript
printNativeData(options: { data: string; }) => void
```

| Param         | Type                           |
| ------------- | ------------------------------ |
| **`options`** | <code>{ data: string; }</code> |

--------------------


### printReferenceLabel(...)

```typescript
printReferenceLabel(options: { labeltype: ReferenceTicketType; }) => void
```

| Param         | Type                                                                                |
| ------------- | ----------------------------------------------------------------------------------- |
| **`options`** | <code>{ labeltype: <a href="#referencetickettype">ReferenceTicketType</a>; }</code> |

--------------------


### requestPermission(...)

```typescript
requestPermission(options: { permission: string; }) => Promise<{ result: boolean; }>
```

| Param         | Type                                 |
| ------------- | ------------------------------------ |
| **`options`** | <code>{ permission: string; }</code> |

**Returns:** <code>Promise&lt;{ result: boolean; }&gt;</code>

--------------------


### requestAllPermissions(...)

```typescript
requestAllPermissions(options: { permissions: string[]; }) => Promise<{ result: boolean; }>
```

| Param         | Type                                    |
| ------------- | --------------------------------------- |
| **`options`** | <code>{ permissions: string[]; }</code> |

**Returns:** <code>Promise&lt;{ result: boolean; }&gt;</code>

--------------------


### sendFormFeed()

```typescript
sendFormFeed() => void
```

--------------------


### setAutoReconnect(...)

```typescript
setAutoReconnect(options: { autoreconnect: boolean; }) => void
```

| Param         | Type                                     |
| ------------- | ---------------------------------------- |
| **`options`** | <code>{ autoreconnect: boolean; }</code> |

--------------------


### setConfiguration(...)

```typescript
setConfiguration(options: { config: PrinterConfiguration; }) => void
```

| Param         | Type                                                                               |
| ------------- | ---------------------------------------------------------------------------------- |
| **`options`** | <code>{ config: <a href="#printerconfiguration">PrinterConfiguration</a>; }</code> |

--------------------


### setLTSSensitivity(...)

```typescript
setLTSSensitivity(options: { sensitivity: number; }) => void
```

| Param         | Type                                  |
| ------------- | ------------------------------------- |
| **`options`** | <code>{ sensitivity: number; }</code> |

--------------------


### setTimeouts(...)

```typescript
setTimeouts(options: CIDPrintTimeoutOptions) => void
```

| Param         | Type                                                                      | Description                   |
| ------------- | ------------------------------------------------------------------------- | ----------------------------- |
| **`options`** | <code><a href="#cidprinttimeoutoptions">CIDPrintTimeoutOptions</a></code> | timeout configuration values. |

--------------------


### setupMediaSize(...)

```typescript
setupMediaSize(options: { width: number; height: number; }) => void
```

| Param         | Type                                            |
| ------------- | ----------------------------------------------- |
| **`options`** | <code>{ width: number; height: number; }</code> |

--------------------


### showNavigationBar(...)

```typescript
showNavigationBar(options: { show: boolean; }) => void
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ show: boolean; }</code> |

--------------------


### showSettings(...)

```typescript
showSettings(options: { show: boolean; }) => void
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ show: boolean; }</code> |

--------------------


### showUI(...)

```typescript
showUI(options: { show: boolean; }) => void
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ show: boolean; }</code> |

--------------------


### uploadFile(...)

```typescript
uploadFile(options: { file: string; filetype: number; }) => void
```

| Param         | Type                                             |
| ------------- | ------------------------------------------------ |
| **`options`** | <code>{ file: string; filetype: number; }</code> |

--------------------


### addListener(string, ...)

```typescript
addListener(eventName: string, listenerFunc: (data: PrinterLibraryEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
```

| Param              | Type                                                                                   |
| ------------------ | -------------------------------------------------------------------------------------- |
| **`eventName`**    | <code>string</code>                                                                    |
| **`listenerFunc`** | <code>(data: <a href="#printerlibraryevent">PrinterLibraryEvent</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => void
```

--------------------


### Interfaces


#### PrinterLibraryEvent

| Prop          | Type                                                                          |
| ------------- | ----------------------------------------------------------------------------- |
| **`sender`**  | <code>string</code>                                                           |
| **`type`**    | <code><a href="#eventtype">EventType</a></code>                               |
| **`message`** | <code>string</code>                                                           |
| **`error`**   | <code>number</code>                                                           |
| **`data`**    | <code><a href="#resultclass">ResultClass</a></code>                           |
| **`action`**  | <code><a href="#printerlibraryactiontype">PrinterLibraryActionType</a></code> |


#### ResultClass


#### MediaSize

| Prop         | Type                |
| ------------ | ------------------- |
| **`width`**  | <code>number</code> |
| **`height`** | <code>number</code> |


#### CIDPrinterInformation

| Prop                       | Type                                          |
| -------------------------- | --------------------------------------------- |
| **`firmware`**             | <code><a href="#firmware">Firmware</a></code> |
| **`main_firmware`**        | <code><a href="#firmware">Firmware</a></code> |
| **`module_firmware`**      | <code><a href="#firmware">Firmware</a></code> |
| **`sensor_boot_firmware`** | <code><a href="#firmware">Firmware</a></code> |
| **`sensor_firmware`**      | <code><a href="#firmware">Firmware</a></code> |
| **`media`**                | <code><a href="#media">Media</a></code>       |
| **`battery`**              | <code><a href="#battery">Battery</a></code>   |
| **`modeltype`**            | <code>number</code>                           |
| **`modelname`**            | <code>string</code>                           |
| **`dpi`**                  | <code>number</code>                           |
| **`dots_mm`**              | <code>number</code>                           |
| **`dots`**                 | <code>number</code>                           |
| **`lanaddress`**           | <code>string</code>                           |
| **`wlanaddress`**          | <code>string</code>                           |
| **`btaddress`**            | <code>string</code>                           |
| **`headcount`**            | <code>string</code>                           |
| **`lifecount`**            | <code>string</code>                           |
| **`cutcount`**             | <code>string</code>                           |
| **`dispensecount`**        | <code>string</code>                           |
| **`thermotransfer`**       | <code>boolean</code>                          |


#### Firmware

| Prop           | Type                |
| -------------- | ------------------- |
| **`version`**  | <code>string</code> |
| **`date`**     | <code>string</code> |
| **`checksum`** | <code>string</code> |


#### Media

| Prop              | Type                |
| ----------------- | ------------------- |
| **`labelwidth`**  | <code>number</code> |
| **`labelheight`** | <code>number</code> |


#### Battery

| Prop             | Type                |
| ---------------- | ------------------- |
| **`cyclecount`** | <code>number</code> |
| **`chargestat`** | <code>number</code> |
| **`health`**     | <code>number</code> |
| **`remain`**     | <code>number</code> |


#### TicketData

| Prop            | Type                                                      |
| --------------- | --------------------------------------------------------- |
| **`variables`** | <code><a href="#ticketvariable">TicketVariable</a></code> |


#### TicketVariable


#### PrinterConfiguration

| Prop                      | Type                                          |
| ------------------------- | --------------------------------------------- |
| **`disconnectonpause`**   | <code>boolean</code>                          |
| **`connectonresume`**     | <code>boolean</code>                          |
| **`lowbatterythreshold`** | <code>number</code>                           |
| **`media`**               | <code><a href="#cidmedia">CIDMedia</a></code> |


#### CIDMedia

| Prop       | Type                                            |
| ---------- | ----------------------------------------------- |
| **`size`** | <code><a href="#mediasize">MediaSize</a></code> |
| **`type`** | <code><a href="#mediatype">MediaType</a></code> |


#### CIDPrintTimeoutOptions

| Prop              | Type                | Description                                                                                                                                                  |
| ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`gap`**         | <code>number</code> | the time the communication protocol waits between send and receive calls (default 0ms)                                                                       |
| **`timeout`**     | <code>number</code> | the time the communication protocol waits for a connection request (default 18000ms)                                                                         |
| **`status`**      | <code>number</code> | the time the communication protocol waits for the answer to a status request (default 500ms)                                                                 |
| **`information`** | <code>number</code> | the time the communication protocol waits for the answer to the request for the printerinformation (default 1000ms)                                          |
| **`formfeed`**    | <code>number</code> | the time the communication protocol waits for the answer to the request for a formfeed (default 200ms)                                                       |
| **`detect`**      | <code>number</code> | the time the communication protocol waits for the answer to the request for the printerinformation (default 400ms) only used with old SATO printers(MB200i). |


#### PluginListenerHandle

| Prop         | Type                                      |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


### Enums


#### EventType

| Members       | Value          |
| ------------- | -------------- |
| **`SUCCESS`** | <code>0</code> |
| **`NOTIFY`**  | <code>1</code> |
| **`FAILED`**  | <code>2</code> |


#### PrinterLibraryActionType

| Members                    | Value           |
| -------------------------- | --------------- |
| **`NONE`**                 | <code>0</code>  |
| **`INITIALIZE`**           | <code>1</code>  |
| **`BLUETOOTH_INITIALIZE`** | <code>2</code>  |
| **`BLUETOOTH_ENABLE`**     | <code>3</code>  |
| **`BLUETOOTH_DISABLE`**    | <code>4</code>  |
| **`DISCOVER_START`**       | <code>5</code>  |
| **`DISCOVER_DETECT`**      | <code>6</code>  |
| **`DISCOVER_FINISH`**      | <code>7</code>  |
| **`CONNECT`**              | <code>8</code>  |
| **`DISCONNECT`**           | <code>9</code>  |
| **`PRINT`**                | <code>10</code> |
| **`STATUS`**               | <code>11</code> |
| **`CONFIGURE`**            | <code>12</code> |
| **`BLUETOOTH_TURNED_OFF`** | <code>13</code> |
| **`BLUETOOTH_TURNED_ON`**  | <code>14</code> |
| **`LICENSE_ACTIVATION`**   | <code>15</code> |
| **`FILEUPLOAD`**           | <code>16</code> |
| **`EXCEPTION`**            | <code>17</code> |


#### ReferenceTicketType

| Members          | Value          |
| ---------------- | -------------- |
| **`DOT_MATRIX`** | <code>0</code> |


#### MediaType

| Members     | Value          |
| ----------- | -------------- |
| **`GAP`**   | <code>0</code> |
| **`IMARK`** | <code>1</code> |

</docgen-api>

### initCIDPrinterLib(): Promise<{event: PrinterLibraryEvent}>

```javascript
await initCIDPrinterLib();
```
Version 0.1.0
Parameters: - __none__

[code sample](#initCIDPrint)
#
### closeCIDPrinterLib()

```javascript
await closeCIDPrinterLib();
```
Version 0.1.0
Parameters: - __none__

### activateLicense

```javascript
await activateLicense(key: string, customer: string);
```
Version 0.1.0
Parameters:
- __key__ *(string)* - valid Licensekey.
- __customer__ *(string)* - valid CustomerId.

#

### enableBluetoothPrinting

```javascript
await enableBluetoothPrinting(enable: boolean);
```
Version 1.0.0
Parameters:
- __enable__ *(boolean)* - Enables/disables the Printing via  Bluetooth.

#

### getPairedDevices

```javascript
getPairedDevices();
```
Version 0.1.0

Parameters:- __none__

#

### discoverDevices

```javascript
discoverDevices();
```
Version 0.1.0

Parameters:- __none__

#

### printData

```javascript
printData(data: string);
```
Version 0.1.0

Parameters:
- __data__ *(string)* - data to be printed.

#

### printLabelWithData

```javascript
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

```javascript
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

```javascript
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.

#

## Examples

### initCIDPrint

```javascript
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.
    }
  }
}
```


### Discover printers

```hint
For the sample code to work it is required to call initCIDPrinter and enableBlutoothPrinting.
```

Register the callback method for the discover procedure

```javascript
  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

## Examples


```javascript
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;

```
