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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-printer-usb

v0.3.1

Published

React Native module to print on USB thermal printers

Downloads

56

Readme

react-native-printer-usb

React Native module to print on USB thermal printers (ESC/POS) for Android. Supports text, images (base64/URL), barcodes, QR codes, HTML, and raw commands. Handles accented characters, alignment, font, cut, beep, underline, and more.

Installation

npm install react-native-printer-usb

Android Setup

  • No manual steps required for most React Native projects (autolinking).
  • For custom setups, ensure USB permissions in AndroidManifest.xml:
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />

Usage

List Devices

import { getList } from 'react-native-printer-usb';
const devices = getList();
// [{ vendorId, productId, deviceId, manufacturerName, productName, serialNumber, deviceName }]

Print Text

import { printText } from 'react-native-printer-usb';
await printText({
  text: 'Olá, mundo! Çãõé',
  productId, // required
  align: 'center', // 'left' | 'center' | 'right'
  encoding: 'CP850', // or 'utf8', 'ISO-8859-1', etc.
  bold: true,
  underline: true,
  font: 'A', // 'A' | 'B' | 'C'
  size: 2, // 1 (normal), 2 (2x), 4 (4x)
  cut: true, // cut paper after print
  beep: true, // beep after print
  tailingLine: true, // add blank lines at end
});

Print Image (Base64 or URL)

import { printImageBase64, printImageUri } from 'react-native-printer-usb';
await printImageBase64({ base64Image, productId, align: 'center' });
await printImageUri({ imageUri: 'https://...', productId, align: 'center' });

Print Barcode / QR Code

import { barCode, qrCode } from 'react-native-printer-usb';
await barCode({ text: '123456789012', productId, width: 2, height: 80 });
await qrCode({ text: 'https://reactnative.dev', productId, size: 6, align: 'center' });

Print HTML

import { printHtml } from 'react-native-printer-usb';
await printHtml({
  html: '<h1>Impressão HTML</h1>',
  productId,
  align: 'center',
  htmlHeight: 760, // px (optional)
});

Send Raw Data

import { sendRawData } from 'react-native-printer-usb';
await sendRawData({
  productId,
  text: '\x1B\x40Hello\n', // ESC/POS commands
  cut: true,
  tailingLine: true,
  encoding: 'utf8',
});

Cut, Reset, Beep

import { printCut, reset } from 'react-native-printer-usb';
await printCut(true, true, productId); // cut, beep, productId
await reset(productId);

Options Reference

| Option | Type | Description | | -------------- | --------- | -------------------------------------------- | | text | string | Text to print | | productId | number | USB Product ID (required) | | align | string | 'left', 'center', 'right' | | encoding | string | 'utf8', 'CP850', 'ISO-8859-1', etc. | | bold | boolean | Bold text | | underline | boolean | Underline text | | font | string | 'A', 'B', 'C' | | size | number | 1 (normal), 2 (2x), 4 (4x) | | cut | boolean | Cut paper after print | | beep | boolean | Beep after print | | tailingLine | boolean | Add blank lines at end | | base64Image | string | PNG/JPG base64 image (for printImageBase64) | | imageUri | string | Image URL (for printImageUri) | | html | string | HTML string (for printHtml) | | htmlHeight | number | Height in px for HTML print (optional) |

Example App

See example/App.tsx for a full-featured demo with device selection, all print types, and UI/UX best practices.

Troubleshooting

  • Certifique-se de que o dispositivo USB está conectado e com permissão.
  • Use encoding compatível com sua impressora (CP850, ISO-8859-1, etc).
  • Para imagens, use PNG/JPG pequenos e alinhamento adequado.
  • Para impressoras que não cortam/beep, ignore as opções cut/beep.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library