🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

react-native-printer-usb

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-printer-usb

React Native module to print on USB thermal printers

latest
Source
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

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

OptionTypeDescription
textstringText to print
productIdnumberUSB Product ID (required)
alignstring'left', 'center', 'right'
encodingstring'utf8', 'CP850', 'ISO-8859-1', etc.
boldbooleanBold text
underlinebooleanUnderline text
fontstring'A', 'B', 'C'
sizenumber1 (normal), 2 (2x), 4 (4x)
cutbooleanCut paper after print
beepbooleanBeep after print
tailingLinebooleanAdd blank lines at end
base64ImagestringPNG/JPG base64 image (for printImageBase64)
imageUristringImage URL (for printImageUri)
htmlstringHTML string (for printHtml)
htmlHeightnumberHeight 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

Keywords

react-native

FAQs

Package last updated on 17 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts