quick_print
विभिन्न प्लेटफॉर्म और उपकरणों पर PDF प्रिंटिंग के लिए एक व्यापक Flutter पैकेज, जिसमें ESC/POS, Sunmi, ब्लूटूथ, USB और सिस्टम प्रिंटर जैसे विभिन्न प्रिंटर प्रकार का समर्थन होता है।
इस पैकेज में विभिन्न प्रिंटर प्रकारों के उपयोग करके PDF प्रिंट करने के लिए एक समन्वित इंटरफ़ेस प्रदान करता है, जिसमें ESC/POS, Sunmi, ब्लूटूथ, USB और सिस्टम प्रिंटर शामिल हैं।
^11.4.0^2.0.4{"sdk":"flutter"}^1.2.12^3.11.3^2.9.0^5.14.2^4.1.0^1.1.1^4.5.4^2.1.5^5.0.0{"sdk":"flutter"}^1.24.0यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
A comprehensive Flutter package for handling PDF printing across different platforms and devices. This package provides a unified interface for printing PDFs using various printer types, including ESC/POS, Sunmi, Bluetooth, USB, and system printers.
Add this to your package's pubspec.yaml file:
dependencies:
quick_print: <LASTEST_VERSION>
Then run:
flutter pub get
import 'package:quick_print/quick_print.dart';
// Create a printer instance
final printer = QuickPrint(PrinterDeviceType.mobile);
// Print a PDF file
await printer.instance.print(
path: 'assets/document.pdf',
paperSize: PaperSize.a4,
);
// Print an image (as Uint8List)
final imageBytes = await File('assets/image.png').readAsBytes();
await printer.instance.printImage(
bytes: imageBytes,
paperSize: PaperSize.a4,
);
The PrinterDiscoveryService class allows you to discover printers on various platforms.
import 'package:quick_print/quick_print.dart';
final discoveryService = PrinterDiscoveryService();
// Initialize the service (required for BLE on Windows)
await discoveryService.initialize();
// Discover printers
await discoveryService.discoverDevices();
// List discovered printers
final printers = discoveryService.printerDevicesList;
printers.forEach((printer) {
print('Discovered printer: ${printer.name}');
});
// Dispose of the service when done
discoveryService.dispose();
import 'package:quick_print/quick_print.dart';
// Create a Bluetooth printer model
final bluetoothModel = BluetoothPrinterModel(
name: 'Thermal Printer',
address: '00:11:22:33:44:55',
isBle: false,
);
// Create a printer instance
final printer = QuickPrint(PrinterDeviceType.bluetooth);
// Print with the Bluetooth printer
await printer.instance.print(
path: 'assets/receipt.pdf',
paperSize: PaperSize.mm80,
model: bluetoothModel,
);
import 'package:quick_print/quick_print.dart';
// Create a USB printer model
final usbModel = UsbPrinterModel(
name: 'POS-58',
productId: '0x0483',
vendorId: '0x5740',
);
// Create a printer instance
final printer = QuickPrint(PrinterDeviceType.usb);
// Print with the USB printer
await printer.instance.print(
path: 'assets/receipt.pdf',
paperSize: PaperSize.mm58,
model: usbModel,
);
Add the following permissions to your AndroidManifest.xml:
<!-- For Bluetooth printers -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<!-- For USB printers -->
<uses-feature android:name="android.hardware.usb.host"/>
Add the following to your Info.plist:
<key>UISupportedExternalAccessoryProtocols</key>
<array>
<string>com.printer.protocol</string>
</array>
<!-- For Bluetooth printers -->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need BT access for printing</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need BT access for printing</string>
Add the following entitlements to your app:
com.apple.security.print
com.apple.security.device.usb
com.apple.security.device.bluetooth
The package uses custom exceptions for error handling:
PrinterException: General printer errorsInvalidFileException: Errors related to invalid filesInvalidTypeException: Errors for invalid printer modelsUnConnectedDeviceException: Errors for unconnected devicesExample:
try {
await printer.instance.print(
path: 'assets/document.pdf',
paperSize: PaperSize.a4,
);
} on PrinterException catch (e) {
print('Printing failed: ${e.message}');
if (e.cause != null) {
print('Cause: ${e.cause}');
}
}
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions, please:
/// Printer implementation for USB-connected printers. class UsbPrinter extends IConnectionPrinter { }