How can I connect already loaded PDF into bluetooth thermal printer.
How can I connect already loaded PDF into bluetooth thermal printer.
How can I connect already loaded PDF into bluetooth thermal printer.
How can I connect already loaded PDF into bluetooth thermal printer.
Add the following plugin in pubspec.yaml
:
dependencies:
path_provider: ^1.6.27
Update the version number to whatever is current.
And import it in your code.
import 'package:path_provider/path_provider.dart';
You also have to import dart:io
to use the File class.
import 'dart:io';
Future <List<int>> _readPDFFile() async {
try {
final Directory directory = await getApplicationDocumentsDirectory();
final File file = File('${directory.path}/my_file.pdf');
final bytes = File(file.path).readAsBytesSync();
} catch (e) {
print("Couldn't read file");
}
return bytes;
}
use thermal printer package link = bluetooth_thermal_printer: ^0.0.6
finally send those bytes data into thermal printer
Future<void> printRecipientPaper() async {
String isConnected = await BluetoothThermalPrinter.connectionStatus;
if (isConnected == "true") {
List<int> bytes = await _readPDFFile();
final result = await BluetoothThermalPrinter.writeBytes(bytes);
print("Print $result");
} else {
//Hadnle Not Connected Senario
}
}
if you have image in pdf file you can follow below link as well How to convert a PDF file to an image with Flutter?