### Run example application Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Commands to start the packager and run the example application on Android or iOS platforms. ```sh yarn example start ``` ```sh yarn example android ``` ```sh yarn example ios ``` -------------------------------- ### Install dependencies Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Run this command in the root directory to install all required project dependencies. ```sh yarn ``` -------------------------------- ### Install react-native-xprinter-thermal Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/README.md Use yarn to add the library to your React Native project. ```sh yarn add react-native-xprinter-thermal ``` -------------------------------- ### Run unit tests Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Execute the project's unit test suite. ```sh yarn test ``` -------------------------------- ### Publish new versions Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Use release-it to handle version bumping, tagging, and publishing to npm. ```sh yarn release ``` -------------------------------- ### Execute a complete shipping label print workflow Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Demonstrates the full lifecycle of connecting to a printer, configuring label dimensions, adding content, printing, and disconnecting. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function printShippingLabel(orderData: { orderId: string; productName: string; destination: string; }) { try { // Step 1: Connect to printer await XprinterThermal.connectNet('192.168.10.222', 9100); // Step 2: Configure label size (100mm x 150mm shipping label) XprinterThermal.setLabelSize(100, 150); XprinterThermal.setLabelGap(3, 0); // Step 3: Add barcode for order ID XprinterThermal.addPrintBarcode( 50, 20, '128', 100, 1, 0, 2, 2, orderData.orderId ); // Step 4: Add product name text XprinterThermal.addPrintText( 50, 140, '2', 0, 1, 1, `Product: ${orderData.productName}` ); // Step 5: Add destination text XprinterThermal.addPrintText( 50, 180, '2', 0, 1, 1, `Ship to: ${orderData.destination}` ); // Step 6: Add QR code for tracking XprinterThermal.addPrintQRcode( 50, 220, 'M', 4, 'A', 0, 'M2', 'S7', `https://track.example.com/${orderData.orderId}` ); // Step 7: Print the label await XprinterThermal.print(1); console.log('Label printed successfully'); // Step 8: Disconnect when done await XprinterThermal.disconnectNet(); } catch (error) { console.error('Printing error:', error); throw error; } } // Usage printShippingLabel({ orderId: '19001009', productName: 'Widget A', destination: '123 Main St, City' }); ``` -------------------------------- ### Configure AndroidManifest.xml Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/README.md Register the PosprinterService in your AndroidManifest.xml file to enable printer communication. ```xml ``` -------------------------------- ### Verify code quality Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Commands to run TypeScript type checking and ESLint linting. ```sh yarn typescript yarn lint ``` -------------------------------- ### Printer Connection and Configuration Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Methods for managing network connections and setting physical label dimensions. ```APIDOC ## connectNet ### Description Establishes a network connection to the thermal printer. ### Parameters - **ip** (string) - Required - The IP address of the printer. - **port** (number) - Required - The network port (e.g., 9100). ## disconnectNet ### Description Closes the active network connection to the printer. ## setLabelSize ### Description Configures the physical dimensions of the label. ### Parameters - **height** (number) - Required - Label height in mm. - **width** (number) - Required - Label width in mm. ## setLabelGap ### Description Sets the gap between labels. ### Parameters - **vertical** (number) - Required - Vertical gap. - **horizontal** (number) - Required - Horizontal gap. ``` -------------------------------- ### Printer Service and Configuration Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Methods for managing the native printer service and configuring physical label dimensions. ```APIDOC ## rebindService ### Description Rebinds the native printer service, useful for recovering from service disconnection or reinitializing the module. ### Response - **Promise** - Resolves with "Rebind Success" on completion. ## setLabelSize ### Description Configures the physical dimensions of the label in millimeters. ### Parameters - **width** (number) - Required - Label width in millimeters. - **height** (number) - Required - Label height in millimeters. ``` -------------------------------- ### Configure Android Manifest for Xprinter Service Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Add the Xprinter service to your AndroidManifest.xml file to enable printer functionality. ```xml ``` -------------------------------- ### print Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Executes the print job by sending all queued elements to the printer. ```APIDOC ## print ### Description Executes the print job by sending all queued elements to the printer. The numberLabel parameter specifies how many copies of the label to print. Clears the print buffer after successful printing. ### Parameters - **numberLabel** (number) - Required - Number of copies to print. ### Response - **result** (string) - Returns "Printed!" on success. ``` -------------------------------- ### Define the XprinterThermal TypeScript interface Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Provides the full method signatures available for interacting with the thermal printer module. ```typescript interface IXprinterThermal { isConnected: () => Promise; rebindService: () => Promise; connectNet: (ip: string, port: number) => Promise; disconnectNet: () => Promise; setLabelSize: (height: number, width: number) => void; setLabelGap: (vertical: number, horizontal: number) => void; addPrintText: ( x: number, y: number, font: string, rotation: number, xMultiplication: number, yMultiplication: number, content: string ) => void; addPrintBarcode: ( x: number, y: number, codeType: string, height: number, human: number, rotation: number, narrow: number, wide: number, content: string ) => void; addPrintQRcode: ( x: number, y: number, eccLevel: string, cellWidth: number, mode: string, rotation: number, model: string, mask: string, content: string ) => void; print: (numberLabel: number) => Promise; } ``` -------------------------------- ### Add QR Code to Print Buffer Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Queues a QR code with configurable error correction, size, and model settings. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; // Add standard QR code XprinterThermal.addPrintQRcode( 50, // x position in dots 180, // y position in dots 'M', // ECC level: L (7%), M (15%), Q (25%), H (30%) 4, // cell width (module size) 'A', // mode: A (auto), M (manual) 0, // rotation: 0, 90, 180, 270 'M2', // model: M1 (Model 1), M2 (Model 2) 'S7', // mask pattern: S0-S7 '19001009' // QR code content ); // Add QR code with URL XprinterThermal.addPrintQRcode( 100, 100, 'H', 6, 'A', 0, 'M2', 'S7', 'https://example.com/product/12345' ); // Add smaller QR code with lower error correction XprinterThermal.addPrintQRcode( 50, 50, 'L', 3, 'A', 0, 'M2', 'S7', 'SKU-12345' ); ``` -------------------------------- ### Fix formatting errors Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/CONTRIBUTING.md Automatically fix linting and formatting issues. ```sh yarn lint --fix ``` -------------------------------- ### Connect to Xprinter via Network Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Establishes a network connection to an Xprinter thermal printer using its IP address and port. This must be called before any printing operations. Handles connection success or failure. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function connectToPrinter() { try { const printerIp = '192.168.10.222'; const printerPort = 9100; await XprinterThermal.connectNet(printerIp, printerPort); console.log('Successfully connected to printer'); } catch (error) { console.error('Failed to connect:', error); // Error messages: "Xprinter module is not binded!" or "Connect printer failed!" } } ``` -------------------------------- ### Print Execution Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Method to trigger the printing process. ```APIDOC ## print ### Description Sends the current buffer to the printer to execute the print job. ### Parameters - **numberLabel** (number) - Required - Number of copies to print. ### Response - **Promise** - Returns a status message upon completion. ``` -------------------------------- ### Printer Connection Management Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Methods for establishing, checking, and terminating network connections to Xprinter devices. ```APIDOC ## connectNet ### Description Establishes a network connection to an Xprinter thermal printer using its IP address and port. ### Parameters - **ip** (string) - Required - The IP address of the printer. - **port** (number) - Required - The network port of the printer. ### Response - **Promise** - Resolves on success, rejects with error message if connection fails. ## disconnectNet ### Description Disconnects from the currently connected printer to free up the network connection. ### Response - **Promise** - Resolves on successful disconnection. ## isConnected ### Description Checks the current connection status of the printer. ### Response - **Promise** - Resolves to true if connected, false otherwise. ``` -------------------------------- ### Label Content Composition Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Methods for adding text, barcodes, and QR codes to the print buffer. ```APIDOC ## addPrintText ### Description Adds text content to the label buffer. ### Parameters - **x, y** (number) - Required - Coordinates. - **font** (string) - Required - Font identifier. - **rotation** (number) - Required - Rotation angle. - **xMultiplication, yMultiplication** (number) - Required - Scaling factors. - **content** (string) - Required - The text to print. ## addPrintBarcode ### Description Adds a barcode to the label buffer. ### Parameters - **x, y** (number) - Required - Coordinates. - **codeType** (string) - Required - Barcode symbology (e.g., '128'). - **height** (number) - Required - Barcode height. - **human** (number) - Required - Human readable text flag. - **rotation** (number) - Required - Rotation. - **narrow, wide** (number) - Required - Barcode width parameters. - **content** (string) - Required - Data to encode. ## addPrintQRcode ### Description Adds a QR code to the label buffer. ### Parameters - **x, y** (number) - Required - Coordinates. - **eccLevel** (string) - Required - Error correction level. - **cellWidth** (number) - Required - Width of QR cells. - **mode, rotation, model, mask** (string) - Required - QR configuration parameters. - **content** (string) - Required - Data to encode. ``` -------------------------------- ### addPrintQRcode Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Adds a QR code to the print buffer. ```APIDOC ## addPrintQRcode ### Description Adds a QR code to the print buffer. Parameters include position, error correction level, cell width, encoding mode, rotation, QR model, and mask pattern. ### Parameters - **x** (number) - Required - X position in dots. - **y** (number) - Required - Y position in dots. - **ecc** (string) - Required - ECC level (L, M, Q, H). - **cellWidth** (number) - Required - Cell width (module size). - **mode** (string) - Required - Mode (A, M). - **rotation** (number) - Required - Rotation (0, 90, 180, 270). - **model** (string) - Required - QR model (M1, M2). - **mask** (string) - Required - Mask pattern (S0-S7). - **content** (string) - Required - QR code content. ``` -------------------------------- ### Execute Print Job Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Sends the queued buffer to the printer. The print method is asynchronous and clears the buffer upon completion. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function printLabel() { try { // Print 1 copy of the label const result = await XprinterThermal.print(1); console.log(result); // "Printed!" } catch (error) { console.error('Print failed:', error); // Errors: "The printer is not connected!" or "Cannot print, check native code!" } } // Print multiple copies async function printMultipleLabels() { await XprinterThermal.print(5); // Print 5 copies } ``` -------------------------------- ### Check Xprinter Connection Status Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Checks the current connection status of the printer. Returns a promise that resolves to a boolean indicating whether the printer is currently connected. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function checkConnection() { const connected = await XprinterThermal.isConnected(); if (connected) { console.log('Printer is connected and ready'); } else { console.log('Printer is not connected'); } } ``` -------------------------------- ### Configure Label Dimensions Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Configures the physical dimensions of the label in millimeters. This must be set before adding print elements to ensure proper positioning. Accepts height and width parameters. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; // Set label size to 100mm x 150mm (common shipping label) XprinterThermal.setLabelSize(100, 150); // Set label size to 50mm x 50mm (small product label) XprinterThermal.setLabelSize(50, 50); // Set label size to 40mm x 30mm (barcode label) XprinterThermal.setLabelSize(40, 30); ``` -------------------------------- ### XprinterThermal Interface Definition Source: https://github.com/cafrotos/react-native-xprinter-thermal/blob/master/README.md Reference the IXprinterThermal interface to understand available methods for network connection and printing operations. ```ts import { XprinterThermal } from "react-native-xprinter-thermal"; // ... // Interface for xprinter module interface IXprinterThermal { connectNet: (ip: string, port: number) => Promise; disconnectNet: () => Promise; setLabelSize: (height: number, width: number) => void; setLabelGap: (vertical: number, horizontal: number) => void; addPrintText: ( x: number, y: number, font: string, rotation: number, xMultiplication: number, yMultiplication: number, content: string ) => void; addPrintBarcode: ( x: number, y: number, codeType: string, height: number, human: number, rotation: number, narrow: number, wide: number, content: string ) => void; addPrintQRcode: ( x: number, y: number, eccLevel: string, cellWidth: number, mode: string, rotation: number, model: string, mask: string, content: string ) => void; print: () => Promise; } ``` -------------------------------- ### Add Text to Print Buffer Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Queues text content at specific coordinates with configurable font, rotation, and scaling factors. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; // Add text at position (50, 150) with font "2", no rotation, normal scale XprinterThermal.addPrintText( 50, // x position in dots 150, // y position in dots '2', // font type (1, 2, 3, 4, 5, etc.) 0, // rotation (0, 90, 180, 270 degrees) 1, // x multiplication (horizontal scale) 1, // y multiplication (vertical scale) 'Product Name: Widget A' ); // Add larger text with 2x scale XprinterThermal.addPrintText(50, 200, '3', 0, 2, 2, 'FRAGILE'); // Add rotated text (90 degrees) XprinterThermal.addPrintText(100, 50, '2', 90, 1, 1, 'Side Text'); ``` -------------------------------- ### Configure Label Gap Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Sets the vertical gap and horizontal offset for labels in millimeters. Use 0 for continuous label rolls. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; // Set 3mm vertical gap between labels, no horizontal offset XprinterThermal.setLabelGap(3, 0); // Set 2mm vertical gap with 1mm horizontal offset XprinterThermal.setLabelGap(2, 1); // No gap (continuous labels) XprinterThermal.setLabelGap(0, 0); ``` -------------------------------- ### Rebind Xprinter Native Service Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Rebinds the native printer service. Useful for recovering from service disconnection issues or reinitializing the printer module after app lifecycle events. Logs the result or any errors. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function rebindPrinterService() { try { const result = await XprinterThermal.rebindService(); console.log(result); // "Rebind Success" } catch (error) { console.error('Rebind failed:', error); } } ``` -------------------------------- ### setLabelGap Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Sets the gap between labels on the label roll in millimeters. ```APIDOC ## setLabelGap ### Description Sets the gap between labels on the label roll in millimeters. The vertical parameter defines the gap between labels, and the horizontal parameter sets any horizontal offset. Default is 0mm for both values. ### Parameters - **vertical** (number) - Required - Gap between labels in mm. - **horizontal** (number) - Required - Horizontal offset in mm. ``` -------------------------------- ### Disconnect from Xprinter Network Connection Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Disconnects from the currently connected printer. Should be called when printing operations are complete to free up the network connection. Handles disconnection success or failure. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; async function disconnectFromPrinter() { try { await XprinterThermal.disconnectNet(); console.log('Disconnected from printer'); } catch (error) { console.error('Disconnect failed:', error); // Error: "The printer is not connected!" } } ``` -------------------------------- ### Add Barcode to Print Buffer Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Queues a barcode with specified type, dimensions, and rotation. Supports common formats like Code 128, EAN-13, and Code 39. ```typescript import { XprinterThermal } from 'react-native-xprinter-thermal'; // Add Code 128 barcode XprinterThermal.addPrintBarcode( 50, // x position in dots 0, // y position in dots '128', // code type: "128", "39", "EAN13", "UPCA", etc. 100, // barcode height in dots 1, // human readable: 0=none, 1=below, 2=above 0, // rotation: 0, 90, 180, 270 2, // narrow bar width 2, // wide bar width '19001009' // barcode content ); // Add EAN-13 barcode with text below XprinterThermal.addPrintBarcode( 100, 50, 'EAN13', 80, 1, 0, 2, 4, '4006381333931' ); // Add Code 39 barcode rotated 90 degrees XprinterThermal.addPrintBarcode( 200, 100, '39', 60, 1, 90, 2, 3, 'ITEM123' ); ``` -------------------------------- ### addPrintText Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Adds text content to the print buffer at specified coordinates. ```APIDOC ## addPrintText ### Description Adds text content to the print buffer at specified coordinates. Parameters include position (x, y), font type, rotation angle, and multiplication factors for scaling. The content is queued until the print method is called. ### Parameters - **x** (number) - Required - X position in dots. - **y** (number) - Required - Y position in dots. - **font** (string) - Required - Font type. - **rotation** (number) - Required - Rotation angle (0, 90, 180, 270). - **xMult** (number) - Required - Horizontal scale factor. - **yMult** (number) - Required - Vertical scale factor. - **text** (string) - Required - The text content to print. ``` -------------------------------- ### addPrintBarcode Source: https://context7.com/cafrotos/react-native-xprinter-thermal/llms.txt Adds a barcode to the print buffer. ```APIDOC ## addPrintBarcode ### Description Adds a barcode to the print buffer. Supports various barcode types including Code 128, Code 39, EAN-13, and UPC-A. ### Parameters - **x** (number) - Required - X position in dots. - **y** (number) - Required - Y position in dots. - **type** (string) - Required - Barcode type (e.g., "128", "39", "EAN13", "UPCA"). - **height** (number) - Required - Barcode height in dots. - **readable** (number) - Required - Human readable text visibility (0=none, 1=below, 2=above). - **rotation** (number) - Required - Rotation (0, 90, 180, 270). - **narrow** (number) - Required - Narrow bar width. - **wide** (number) - Required - Wide bar width. - **content** (string) - Required - Barcode content. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.