npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rdlabo/capacitor-brotherprint

v6.4.4

Published

Capacitor plugin for Brother Print SDK

Downloads

1,003

Readme

@rdlabo/capacitor-brotherprint

Capacitor Brother Print is a native Brother Print SDK implementation for iOS & Android. Support These models.

This plugin is still in the RC (release candidate) phase.

Supported models

Each product link is an Amazon affiliate link. If you choose to make a purchase through these links, it would be greatly appreciated and would help support development costs. Thank you!

| Product | Model | iOS/WiFi | iOS/BT | iOS/BLE | Android/USB | Android/WiFi | Android/BT | Android/BLE | | ------------------------------------- | ------------ | -------- | ------ | ------- | ----------- | ------------ | ---------- | ----------- | | QL-810W | QL_810W | ✗ | ✗ | ✗ | ◯ | ✗ | ✗ | ✗ | | QL-820NWB | QL_820NWB | ◯ | ※1 | ✗ | △ | ◯ | △ | ✗ | | QL-820NWBc | QL_820NWB | ◯ | ※2 | ✗ | ✗ | ◯ | ◯ | ✗ | | TD-2320D | TD_2320D_203 | ✗ | ✗ | ✗ | △ | ✗ | ✗ | ✗ | | TD-2350D | TD_2350D_300 | ◯ | △ | △ | ◯ | ◯ | ◯ | △ |

Amazon Affiliate Links: https://amzn.to/3AiiOFT

Supplement

| | description | | --- | -------------------------- | | ◯ | Supported and tested | | △ | Implemented but not tested | | - | Plugin is not supported | | ✗ | Device is not supported | | BT | Bluetooth | | BLE | Bluetooth Low Energy |

※1 Due to low Bluetooth version, connection is not possible with iOS. Ref: https://okbizcs.okwave.jp/brother/qa/q9932082.html

※2 The iOS/BT implementation for the QL-820NWBc is in place, but it’s uncertain if it functions correctly. It’s unclear whether this is an implementation issue, as Brother’s official app also doesn’t work well.

How to install

% npm install @rdlabo/capacitor-brotherprint

Initialize the Brother SDK

Android configuration

  1. Place the following files in the android folder of your Capacitor project:
  • android/BrotherPrintLibrary/BrotherPrintLibrary.aar
  • android/BrotherPrintLibrary/build.gradle

The BrotherPrintLibrary.aar file is the Brother Print SDK library, which you can download from the Brother website: https://support.brother.co.jp/j/s/es/dev/ja/mobilesdk/android/index.html?c=jp&lang=ja&navi=offall&comple=on&redirect=on#ver4

  1. In the android/BrotherPrintLibrary/build.gradle file, include the following content:
configurations.maybeCreate(“default”)
artifacts.add(“default”, file('BrotherPrintLibrary.aar'))
  1. Open android/settings.gradle and add the following lines:
include ':BrotherPrintLibrary'
project(':BrotherPrintLibrary').projectDir = new File('./BrotherPrintLibrary/')

These steps will integrate the Brother Print SDK with your Capacitor Android project.

iOS configuration

Update the ios/App/Podfile file at your project. https://github.com/BernardRadman/BRLMPrinterKit 's SDK is version 4.7.2. This is old. So should link to direct own repository.

  target 'App' do
    capacitor_pods
    # Add your Pods here
+   pod 'BRLMPrinterKit_v4', :git => 'https://github.com/rdlabo/BRLMPrinterKit.git', :branch => 'feat/update_4_9_1'
  end

After set, run pod update in the ios directory.

Permission configuration

Android configuration

Update AndroidManifest.xml to include the following permissions:

- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools">
...
+     <!-- For Bluetooth -->
+     <uses-permission android:name="android.permission.BLUETOOTH" />
+     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+     <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

+     <!-- For Bluetooth Low Energy, Android 11 and earlier-->
+     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

+     <!-- For Bluetooth Low Energy, Android 12 and later -->
+     <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
+         android:usesPermissionFlags="neverForLocation"
+         tools:targetApi="s" />

More information is here: https://support.brother.co.jp/j/s/support/html/mobilesdk/guide/getting-started/getting-started-android.html

iOS configuration

Update Info.plist to include the following permissions:

+ <key>NSBluetoothAlwaysUsageDescription</key>
+ <string>【Why use Bluetooth for your app.】</string>
+ <key>NSBluetoothPeripheralUsageDescription</key>
+ <string>【Why use Bluetooth for your app.】</string>
+ <key>NSBonjourServices</key>
+ <array>
+ 	<string>_pdl-datastream._tcp</string>
+ 	<string>_printer._tcp</string>
+ 	<string>_ipp._tcp</string>
+ </array>
+ <key>NSLocalNetworkUsageDescription</key>
+ <string>【Why use WiFi for your app.】</string>
+ <key>UISupportedExternalAccessoryProtocols</key>
+ <string>com.brother.ptcbp</string>

More information is here: https://support.brother.co.jp/j/s/support/html/mobilesdk/guide/getting-started/getting-started-ios.html

How to use

@Component({
  selector: 'brother-print',
  templateUrl: 'brother.component.html',
  styleUrls: ['brother.component.scss'],
})
export class BrotherComponent implements OnInit, OnDestroy {
  readonly #listenerHandlers: PluginListenerHandle[] = [];
  readonly printers = signal<BRLMChannelResult[]>([]);

  async ngOnInit() {
    this.#listenerHandlers.push(
      await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrint, () => {
        console.log('onPrint');
      }),
    );
    this.#listenerHandlers.push(
      await BrotherPrint.addListener(
        BrotherPrintEventsEnum.onPrintError,
        info => {
          console.log('onPrintError');
        },
      ),
    );
    this.#listenerHandlers.push(
      await BrotherPrint.addListener(
        BrotherPrintEventsEnum.onPrintFailedCommunication,
        info => {
          console.log('onPrintFailedCommunication');
        },
      ),
    );
    this.#listenerHandlers.push(
      await BrotherPrint.addListener(
        BrotherPrintEventsEnum.onPrinterAvailable,
        printer => {
          this.printers.update(prev => [...prev, printer]);
        },
      ),
    );
  }

  async ngOnDestroy() {
    this.#listenerHandlers.forEach(handler => handler.remove());
  }

  async searchPrinter(port: BRKMPrinterPort) {
    // This method return void. Get the printer list by listening to the event.
    await BrotherPrint.search({
      port,
      searchDuration: 15, // seconds
    });
  }

  print() {
    if (this.printers().length === 0) {
      console.error('No printer found');
      return;
    }

    const defaultPrintSettings: BRLMPrintOptions = {
      modelName: BRLMPrinterModelName.QL_820NWB,
      labelName: BRLMPrinterLabelName.RollW62,
      encodedImage: 'base64 removed mime-type', // base64
      numberOfCopies: 1, // default 1
      autoCut: true, // default true
    };

    BrotherPrint.printImage({
      ...defaultPrintSettings,
      ...{
        port: this.printers()[0].port,
        channelInfo: this.printers()[0].channelInfo,
      },
    });
  }
}

See demo for complete code: https://github.com/rdlabo-team/capacitor-brotherprint/blob/main/demo/src/app/home/home.page.ts

API

printImage(...)

printImage(options: BRLMPrintOptions) => Promise<void>

| Param | Type | | ------------- | ------------------------------------------------------------- | | options | BRLMPrintOptions |


search(...)

search(option: BRLMSearchOption) => Promise<void>

Search for printers. If not found, it will return an empty array.(not error)

| Param | Type | | ------------ | ------------------------------------------------------------- | | option | BRLMSearchOption |


cancelSearchWiFiPrinter()

cancelSearchWiFiPrinter() => Promise<void>

Basically, it times out, so there is no need to use it. Use it when you want to run multiple connectType searches at the same time and time out any of them manually.


cancelSearchBluetoothPrinter()

cancelSearchBluetoothPrinter() => Promise<void>

Basically, it times out, so there is no need to use it. Use it when you want to run multiple connectType searches at the same time and time out any of them manually.


addListener(BrotherPrintEventsEnum.onPrinterAvailable, ...)

addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc: (printers: BRLMChannelResult) => void) => Promise<PluginListenerHandle>

Find the printer that can connected to the device.

| Param | Type | | ------------------ | -------------------------------------------------------------------------------------------- | | eventName | BrotherPrintEventsEnum.onPrinterAvailable | | listenerFunc | (printers: BRLMChannelResult) => void |

Returns: Promise<PluginListenerHandle>


addListener(BrotherPrintEventsEnum.onPrint, ...)

addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void) => Promise<PluginListenerHandle>

Success Print Event

| Param | Type | | ------------------ | --------------------------------------------------------------------------------- | | eventName | BrotherPrintEventsEnum.onPrint | | listenerFunc | () => void |

Returns: Promise<PluginListenerHandle>


addListener(BrotherPrintEventsEnum.onPrintFailedCommunication, ...)

addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>

Failed to connect to the printer. ex: Bluetooth is off, Printer is off, etc.

| Param | Type | | ------------------ | ---------------------------------------------------------------------------------------------------- | | eventName | BrotherPrintEventsEnum.onPrintFailedCommunication | | listenerFunc | (info: ErrorInfo) => void |

Returns: Promise<PluginListenerHandle>


addListener(BrotherPrintEventsEnum.onPrintError, ...)

addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>

Failed to print.

| Param | Type | | ------------------ | -------------------------------------------------------------------------------------- | | eventName | BrotherPrintEventsEnum.onPrintError | | listenerFunc | (info: ErrorInfo) => void |

Returns: Promise<PluginListenerHandle>


Interfaces

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

Type Aliases

BRLMPrintOptions

{ encodedImage: string; /** * Should use enum BRLMPrinterModelName */ modelName: BRLMPrinterModelName; } & Partial<BRLMChannelResult> & (BRLMPrinterQLModelSettings | BRLMPrinterTDModelSettings)

Partial

Make all properties in T optional

{ [P in keyof T]?: T[P]; }

BRLMChannelResult

{ port: BRLMPrinterPort; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string; /** * This need to connect to the printer. * wifi: IP Address * bluetooth: macAddress * bluetoothLowEnergy: modelName for bluetoothLowEnergy */ channelInfo: string; }

BRLMPrinterQLModelSettings

{ /** * Should use enum BRLMPrinterLabelName */ labelName: BRLMPrinterLabelName; } & BRLMPrinterSettings

BRLMPrinterSettings

These are optional. If these are not set, default values are assigned by the printer.

{ /** * The number of copies you print. / numberOfCopies?: BRLMPrinterNumberOfCopies; /* * Whether the auto-cut is enabled or not. If true, your printer cut the paper each page. / autoCut?: BRLMPrinterAutoCutType; /* * A scale mode that specifies how your data is scaled in a print area of your printer. / scaleMode?: BRLMPrinterScaleMode; /* * A scale value. This is effective when ScaleMode is ScaleValue. / scaleValue?: BRLMPrinterScaleValueType; /* * A way to rasterize your data. / halftone?: BRLMPrinterHalftone; /* * A threshold value. This is effective when the Halftone is Threshold. / halftoneThreshold?: BRLMPrinterHalftoneThresholdType; /* * An image rotation that specifies the angle in which your data is placed in the print area. Rotation direction is clockwise. / imageRotation?: BRLMPrinterImageRotation; /* * A vertical alignment that specifies how your data is placed in the printable area. / verticalAlignment?: BRLMPrinterVerticalAlignment; /* * A horizontal alignment that specifies how your data is placed in the printable area. / horizontalAlignment?: BRLMPrinterHorizontalAlignment; /* * A compress mode that specifies how to compress your data. * note: This is ios only. / compressMode?: BRLMPrinterCompressMode; /* * A priority that is print speed or print quality. Whether or not this has an effect is depend on your printer. */ printQuality?: BRLMPrinterPrintQuality; }

BRLMPrinterNumberOfCopies

number

BRLMPrinterAutoCutType

boolean

BRLMPrinterScaleValueType

number

BRLMPrinterHalftoneThresholdType

number

BRLMPrinterTDModelSettings

{ /** * Should use enum BRKMPrinterCustomPaperType / paperType: BRLMPrinterCustomPaperType; /* * The width of the label. For example, the RD-U04J1 is 60.0 wide. / tapeWidth: number; /* * The length of the label. For example, the RD-U04J1 is 60.0 wide. / tapeLength: number; /* * It is the difference between a sticker and a mount. * For example, the RD-U04J1 is 1.0, 2.0, 1.0, 2.0 / marginTop: number; marginRight: number; marginBottom: number; marginLeft: number; /* * The spacing between seals. For example, the RD-U04J1 is 0.2. / gapLength: number; paperMarkPosition: number; paperMarkLength: number; /* * Should use enum BRKMPrinterCustomPaperUnit. * For example, the RD-U04J1 is mm. */ paperUnit: BRLMPrinterCustomPaperUnit; }

BRLMSearchOption

{ /** * 'usb' is android only, and now developing. / port: BRLMPrinterPort; /* * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }

ErrorInfo

{ message: string; code: number; }

Enums

BRLMPrinterModelName

| Members | Value | | ------------------ | --------------------------- | | QL_800 | 'QL_800' | | QL_810W | 'QL_810W' | | QL_820NWB | 'QL_820NWB' | | TD_2320D_203 | 'TD_2320D_203' | | TD_2030AD | 'TD_2030AD' | | TD_2350D_300 | 'TD_2350D_300' |

BRLMPrinterPort

| Members | Value | | ------------------------ | --------------------------------- | | usb | 'usb' | | wifi | 'wifi' | | bluetooth | 'bluetooth' | | bluetoothLowEnergy | 'bluetoothLowEnergy' |

BRLMPrinterLabelName

| Members | Value | Description | | --------------------- | ------------------------------ | ------------- | | DieCutW17H54 | 'DieCutW17H54' | | | DieCutW17H87 | 'DieCutW17H87' | | | DieCutW23H23 | 'DieCutW23H23' | | | DieCutW29H42 | 'DieCutW29H42' | | | DieCutW29H90 | 'DieCutW29H90' | | | DieCutW38H90 | 'DieCutW38H90' | | | DieCutW39H48 | 'DieCutW39H48' | | | DieCutW52H29 | 'DieCutW52H29' | | | DieCutW62H29 | 'DieCutW62H29' | | | DieCutW62H60 | 'DieCutW62H60' | | | DieCutW62H75 | 'DieCutW62H75' | | | DieCutW62H100 | 'DieCutW62H100' | | | DieCutW60H86 | 'DieCutW60H86' | | | DieCutW54H29 | 'DieCutW54H29' | | | DieCutW102H51 | 'DieCutW102H51' | | | DieCutW102H152 | 'DieCutW102H152' | | | DieCutW103H164 | 'DieCutW103H164' | | | RollW12 | 'RollW12' | | | RollW29 | 'RollW29' | | | RollW38 | 'RollW38' | | | RollW50 | 'RollW50' | | | RollW54 | 'RollW54' | | | RollW62 | 'RollW62' | | | RollW62RB | 'RollW62RB' | | | RollW102 | 'RollW102' | | | RollW103 | 'RollW103' | | | DTRollW90 | 'DTRollW90' | | | DTRollW102 | 'DTRollW102' | | | DTRollW102H51 | 'DTRollW102H51' | | | DTRollW102H152 | 'DTRollW102H152' | | | RoundW12DIA | 'RoundW12DIA' | | | RoundW24DIA | 'RoundW24DIA' | | | RoundW58DIA | 'RoundW58DIA' | | | RDDieCutW60H60 | 'RDDieCutW60H60' | For TD series | | RDDieCutW50H30 | 'RDDieCutW50H30' | | | RDDieCutW40H60 | 'RDDieCutW40H60' | | | RDDieCutW40H50 | 'RDDieCutW40H50' | | | RDDieCutW40H40 | 'RDDieCutW40H40' | | | RDDieCutW30H30 | 'RDDieCutW30H30' | | | RDDieCutW50H35 | 'RDDieCutW50H35' | | | RDDieCutW60H80 | 'RDDieCutW60H80' | | | RDDieCutW60H100 | 'RDDieCutW60H100' | |

BRLMPrinterScaleMode

| Members | Value | | -------------------- | ----------------------------- | | ActualSize | 'ActualSize' | | FitPageAspect | 'FitPageAspect' | | FitPaperAspect | 'FitPaperAspect' | | ScaleValue | 'ScaleValue' |

BRLMPrinterHalftone

| Members | Value | | -------------------- | ----------------------------- | | Threshold | 'Threshold' | | ErrorDiffusion | 'ErrorDiffusion' | | PatternDither | 'PatternDither' |

BRLMPrinterImageRotation

| Members | Value | | --------------- | ------------------------ | | Rotate0 | 'Rotate0' | | Rotate90 | 'Rotate90' | | Rotate180 | 'Rotate180' | | Rotate270 | 'Rotate270' |

BRLMPrinterVerticalAlignment

| Members | Value | | ------------ | --------------------- | | Top | 'Top' | | Center | 'Center' | | Bottom | 'Bottom' |

BRLMPrinterHorizontalAlignment

| Members | Value | | ------------ | --------------------- | | Left | 'Left' | | Center | 'Center' | | Right | 'Right' |

BRLMPrinterCompressMode

| Members | Value | | ----------- | -------------------- | | None | 'None' | | Tiff | 'Tiff' | | Mode9 | 'Mode9' |

BRLMPrinterPrintQuality

| Members | Value | | ---------- | ------------------- | | Best | 'Best' | | Fast | 'Fast' |

BRLMPrinterCustomPaperType

| Members | Value | | ------------------- | ---------------------------- | | rollPaper | 'rollPaper' | | dieCutPaper | 'dieCutPaper' | | markRollPaper | 'markRollPaper' |

BRLMPrinterCustomPaperUnit

| Members | Value | | ---------- | ------------------- | | mm | 'mm' | | inch | 'inch' |

BrotherPrintEventsEnum

| Members | Value | | -------------------------------- | ----------------------------------------- | | onPrinterAvailable | 'onPrinterAvailable' | | onPrint | 'onPrint' | | onPrintFailedCommunication | 'onPrintFailedCommunication' | | onPrintError | 'onPrintError' |