Skip to content

Repository files navigation

Printer

npm version

Features

  • Supports BLE, LAN, USB and Wi-Fi connection methods
  • Print receipts natively and from React Native views
  • Compatible with the new architecture
  • Build-in queue mechanism
  • Clear errors descriptions
  • Proxy-like API makes it easy to add new commands

Installation

React Native

Warning

For react-native lower than 0.76.x version, use react-native-esc-pos-printer 4.3.3 or lower

yarn add react-native-esc-pos-printer

Expo

npx expo install react-native-esc-pos-printer
npx expo prebuild

Also complete this required steps

Usage

Discover printers

import { usePrintersDiscovery } from 'react-native-esc-pos-printer';

function App() {
  const { start, isDiscovering, printers } =
    usePrintersDiscovery();

    useEffect(() => {
      start();
    }, []);
}

Print

import { Printer } from 'react-native-esc-pos-printer';

function App() {
  const { start, isDiscovering, printers } =
    usePrintersDiscovery();

    useEffect(() => {
      start();
    }, []);

    const print = () => {
      // printing on all discovered printers
      printers.forEach(printersData => {
          const printerInstance = new Printer({
            target: printersData.target,
            deviceName: printersData.deviceName,
          });

          const res = await printerInstance.addQueueTask(async () => {
            await Printer.tryToConnectUntil(
              printerInstance,
              (status) => status.online.statusCode === PrinterConstants.TRUE
            );
            await printerInstance.addText('DUDE!');
            await printerInstance.addFeedLine();
            await printerInstance.addCut();
            const result = await printerInstance.sendData();
            await printerInstance.disconnect();
            return result;
        })
      })
  }

  return <Button title="Print" onPress={print} />;
}

Documentation

  1. Discovery API
  2. Printer API
  3. Examples
  4. Supported devices
  5. SDK information (v2.27.0)

Sponsor this project

If you like what I'm doing and want to support me, you can:

Buy me a coffee

Known issues

  1. It's not possible to print and discover on Android simulator.

  2. If you have an issue with using Flipper on iOS real device, try this workaround.

License

MIT

About

[Working on] Epson ECS POS Printer to rescue abandoned original repo and fixes issues and make it work

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages