rn-bluprint-printer
v0.1.5
Published
## Installation
Downloads
1
Maintainers
Readme
rn-bluprint-printer
Installation
npm install rn-bluprint-printerAndroid Setup
Add the following line to the app/build.gradle file in your project.
dependencies {
implementation files('path/to/library/android/libs/PrinterLib_24.aar')
}Usage
import BluePrint from 'rn-bluprint-printer';
// Initialize the printer with callbacks for success and error handling
const initialize = await BluePrint.initiate(
errorCallback,
successCallback
);
// Connect to a specific printer by its name
const connect = await BluePrint.connect(printerName);
// Print data, with optional success and error callbacks
const print = await BluePrint.print(
data,
errorCallback,
successCallback
);
// Retrieve a list of paired Bluetooth devices
const connectedDevices = await BluePrint.getPairedDevices();
Full Example
Here’s a complete example to guide you through each step from initializing the library to printing data.
import { BluePrint } from 'rn-bluprint-printer';
const initializePrinter = async () => {
try {
// Step 1: Initialize the Printer
await BluePrint.initiate(
(error) => console.error("Initialization Error:", error),
() => console.log("Initialization Successful")
);
// Step 2: Get Paired Devices
const pairedDevices = await BluePrint.getPairedDevices();
console.log("Paired Devices:", pairedDevices);
// Step 3: Connect to a Printer
const printerName = pairedDevices[0]?.name || "YourPrinterName";
const isConnected = await BluePrint.connect(printerName);
if (isConnected) {
console.log(`Connected to ${printerName}`);
// Step 4: Print Data
await BluePrint.print(
"Hello, this is a test print!",
(error) => console.error("Print Error:", error),
() => console.log("Print Successful")
);
} else {
console.error(`Failed to connect to printer: ${printerName}`);
}
} catch (error) {
console.error("Error:", error);
}
};
// Initialize and run the example
initializePrinter();
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
