Closed Khamphay closed 1 year ago
did you find any solution for this?
I cann't find a solution, I edited the NetworkPrinterManager.dart file it's still print slow but when print has no issues
I cann't find a solution, I edited the NetworkPrinterManager.dart file it's still print slow but when print has no issues
can you share your solution? I faced this issue
I copy the source code in PrinterNetworkManager file and change _socket.destroy() => _socket.close() on funtion disconnect(...)
import 'dart:io';
import 'dart:typed_data' show Uint8List;
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:image/image.dart';
/// Network Printer
class NetworkPrinterManager {
NetworkPrinterManager(this._paperSize, this._profile,
{int spaceBetweenRows = 5}) {
_generator =
Generator(paperSize, profile, spaceBetweenRows: spaceBetweenRows);
}
final PaperSize _paperSize;
final CapabilityProfile _profile;
String? _host;
int? _port;
late Generator _generator;
late Socket _socket;
late bool isClosed;
bool isPrintCompleted = false;
int? get port => _port;
String? get host => _host;
PaperSize get paperSize => _paperSize;
CapabilityProfile get profile => _profile;
Future<PosPrintResult> connect(String host,
{int port = 91000, Duration timeout = const Duration(seconds: 5)}) async {
_host = host;
_port = port;
try {
_socket = await Socket.connect(host, port, timeout: timeout);
_socket.add(_generator.reset());
isClosed = false;
return Future<PosPrintResult>.value(PosPrintResult.success);
} catch (e) {
isClosed = true;
return Future<PosPrintResult>.value(PosPrintResult.timeout);
}
}
/// [delayMs]: milliseconds to wait after destroying the socket
void disconnect({int? delayMs}) async {
_socket.close();
isClosed = true;
isPrintCompleted = true;
if (delayMs != null) {
await Future.delayed(Duration(milliseconds: delayMs), () => null);
}
}
// ************************ Printer Commands ************************
void reset() {
_socket.add(_generator.reset());
}
void beep({int n = 3, PosBeepDuration duration = PosBeepDuration.beep450ms}) {
_socket.add(_generator.beep(n: n, duration: duration));
isPrintCompleted = true;
}
.
.
.
Whe use
NetworkPrinterManager printer =
NetworkPrinterManager(_paperSize, _profile);
PosPrintResult? result;
result = await printer.connect(
your_ip,9100,
timeout: 300);
if (result != PosPrintResult.success) return;
final imagebill.Image? image = imagebill.decodeImage(your_bill_image);
printer.image(image!);
printer.cut();
printer.beep(n: 1, duration: PosBeepDuration.beep100ms);
if (printer.isPrintCompleted) {
printer.disconnect();
}
Hello, I want to print image but the converted image is larger than the original image size, which it slow to print and cannot resize image before print.