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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-printer-usb

v1.0.9

Published

React Native module to print on USB thermal printers

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) to 8 (8x) — hardware ceiling of the ESC/POS `GS !` command
  cut: true, // cut paper after print
  beep: true, // beep after print
  tailingLine: true, // add blank lines at end
});

Configuring the codepage for your specific printer

Different thermal printers default to different ESC/POS character tables, so accented characters (á, ç, ã...) can print as garbage if the wrong table is assumed. Instead of guessing, pass codepage with the exact table your printer uses — it takes priority over encoding, sends the ESC t select-codepage command to the printer, and encodes the text with the matching charset:

import { printText, codepages } from 'react-native-printer-usb';

await printText({
  text: 'Olá, mundo! Çãõé',
  productId,
  codepage: codepages.CP850, // or codepages.PC860, codepages.WPC1252, ...
});

| Constant | Value | Table | | ------------------ | ----- | --------------------------- | | codepages.PC437 | 0 | USA: Standard Europe | | codepages.CP850 | 2 | Multilingual | | codepages.PC860 | 3 | Portuguese | | codepages.PC863 | 4 | Canadian-French | | codepages.PC865 | 5 | Nordic | | codepages.WPC1252| 16 | Windows-1252 | | codepages.PC866 | 17 | Cyrillic #2 | | codepages.PC852 | 18 | Latin 2 | | codepages.PC858 | 19 | Multilingual + Euro |

Check your printer's manual for the codepage it supports — for Brazilian ESC/POS printers (Gertec, Bematech, Elgin, Daruma, etc.) this is usually CP850 or PC860.

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

Debugging & Error Logs

The library includes a built-in persistent error logger on Android to help diagnose connection, formatting, or hardware issues in production. Logs are saved securely inside the app's private internal storage (usb_printer_errors.log) with precise timestamps and full exception stack traces.

import { getErrorLogs, clearErrorLogs } from 'react-native-printer-usb';

// Retrieve all accumulated error logs as a string
const logs = await getErrorLogs();
console.log(logs);

// Clear the accumulated logs file
const success = await clearErrorLogs();

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. | | codepage | number | ESC t codepage number (see codepages); overrides encoding | | bold | boolean | Bold text | | underline | boolean | Underline text | | font | string | 'A', 'B', 'C' | | size | number | 1 (normal) to 8 (8x); values above 8 are clamped to 8 | | 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