expo-esc-pos-utils
Version:
Expo module for ESC/POS printer utilities, supporting image printing and text formatting
94 lines (62 loc) • 2.79 kB
Markdown
A powerful Expo module for ESC/POS printer utilities, supporting image printing and text formatting. This module provides easy-to-use utilities for working with thermal printers in React Native and Expo applications.
- Image printing support
- Text formatting
- Network printer support
- Base64 image conversion
- ESC/POS command utilities
```bash
npm install expo-esc-pos-utils
yarn add expo-esc-pos-utils
```
```typescript
import ExpoEscPosUtils from 'expo-esc-pos-utils';
import { NetPrinter } from './net-printer';
// Example: Print an image
const printImage = async () => {
const printer = new NetPrinter();
try {
// Connect to printer
await printer.connect('192.168.1.100', 9100);
await printer.initialize();
// Convert and print image
const base64Image = '...'; // Your base64 image string
const intArray = await ExpoEscPosUtils.convertBase64ToGsV0Data(base64Image, 576);
const uint8Array = new Uint8Array(intArray);
await printer.printBitmap(uint8Array);
printer.cut();
} catch (error) {
console.error('Printing error:', error);
} finally {
printer.disconnect();
}
};
```
Converts a base64 image to ESC/POS GS v0 command data.
- `base64`: Base64 encoded image string
- `width`: Width of the image in pixels
- Returns: Promise resolving to an array of numbers representing the ESC/POS command data
Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
MIT
- [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/esc-pos-utils/)
- [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/esc-pos-utils/)
For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
```
npm install expo-esc-pos-utils
```
Run `npx pod-install` after installing the npm package.