I am adding local image from assets folder like this
`
final ByteData data= await rootBundle.load('assets/dol.jpg');
final bytes=data.buffer.asUint8List();
final image= img.decodeImage(bytes);
ticket.image(image);
`
but how can I add image from network to print in bluetooth iam using esc_pos_bluetooth for printing.
I am building a KOT app using flutter. In this I need to split the data into two and send the data to two different thermal printers connected in same network.
Is this possible to do with flutter?
Data is printing in one printer with preview page.
final bytes = await pdf.save();
File file;
final dir = await getApplicationDocumentsDirectory();
file = File('${dir.path}/$name');
await file.writeAsBytes(bytes);
await Printing.layoutPdf(
onLayout: (PdfPageFormat format) async => pdf.save());
I want the data to print in two printers respectively directly without any previews
I made an app that converts images to datr-pdf and prints them. my app prints in Wi-Fi Direct format and uses the printing package. there is no problem in printing using the default print service in both android and IOS. select a printer from the default print service and press the print button after connecting, data is sent to the printer and the app returns to the previous app screen from the default print service screen.
After sending data to the printer, I want to receive a return about success or failure with a bool variable in the process of returning to the previous screen.
My end goal is to pass data from the app to the printer and when I return to the screen of the app, if return is `true', I want the app to close while printing. I'm looking at the source via 'GitHub' but haven't found it yet. Do you know of a method or class that sends data and returns to the app's screen??
My PrintSource
_generatedPdf(PdfPageFormat format, BuildContext context) async {
final pdf = pdfWidget.Document(version: PdfVersion.pdf_1_5, compress: true);
//Page Num
for(int nCount=0; nCount<context.read<ScoreImageProvider>().scoreImageList.length; nCount++){
final image = await imageFromAssetBundle(context.read<ScoreImageProvider>().scoreImageList[nCount]);
pdf.addPage(
pdfWidget.Page(
pageFormat: format,
build: (pdfWidget.Context context){
return pdfWidget.Center(
child: pdfWidget.Padding(
padding: pdfWidget.EdgeInsets.zero,
child: pdfWidget.Image(image, fit: pdfWidget.BoxFit.fill)
)
);
}
)
);
}
bool bRes = await Printing.layoutPdf(onLayout: (format) async => pdf.save());
}
printing package verseion is printing: ^5.6.6 thank you.
Solved
Check if printing is complete in void onCompleted in PrintingHandler.java file.
How to add File to Array (List)
I got an image from ImagePicker
var image = await ImagePicker.pickImage(source: imageSource);
_images are declared by followed
List<File> _images = List<File>();
I tried as Follows
_images = image as List<File>
But I got errors like this
Unhandled Exception: type '_File' is not a subtype of type
'List' in type cast
You're getting the error because Future<File> pickImage(..) returns File not List<File>.
In you code you're trying to cast File as List<File>:
_images = image as List<File>
If you only want to store the File returned from Future<File>pickImage(..), then you can add the File to the List
_images.add(image);
Also Future<File>pickedImage(..) method is deprecated so please try using Future<PickedFile> getImage(..), which returns PickedFile instead of File.
I want to print Hindi language in my PDF, I've also tried using Raleway-Regular.ttf font by Google but it also didn't worked.
final font = await rootBundle.load("fonts/ARIAL.TTF");
final ttf = pw.Font.ttf(font);
pdf.addPage(
pw.MultiPage(
pageFormat: PdfPageFormat.a4,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context){
return <pw.Widget>[
pw.Center(
child: pw.Text("मेन",style: pw.TextStyle(fontSize: 16,font: ttf))
),
pw.SizedBox(height: 20),
pw.Center(
child: pw.Text("ABC",style: pw.TextStyle(fontSize: 16))
),
),
),
I'm getting following Error:
***I/flutter (24862): Cannot decode the string to Latin1.
I/flutter (24862): This font does not support Unicode characters.
I/flutter (24862): If you want to use strings other than Latin strings, use a TrueType (TTF) font instead.
I/flutter (24862): See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
I/flutter (24862): ---------------------------------------------
E/flutter (24862): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid argument (string): Contains invalid characters.: "मेन"
I am also facing the same error its because the fonts you are using does not support that language , if you want to use hindi language then you can use hind-regular.ttl font it supports both the fonts hindi and english.
here is the example what i got.
// step 1- add font locatin in pubspec
fonts:
- family: hind
fonts:
- asset: assets/hind.ttf
//step 2-
final pdf = pw.Document();
final font = await rootBundle.load("assets/hind.ttf");
final ttf = pw.Font.ttf(font);
then just apply this ttf in the fontStyle
packages i m using -
import 'package:universal_html/html.dart' as html;
import 'package:pdf/widgets.dart' as pw;
universal_html: ^1.2.3
enter image description here
pdf: ^1.11.1
Some issues are there with Unicode translations . Please take care of it https://github.com/DavBfr/dart_pdf/issues/198
You can use syncfusion pdf library (You need to buy subscription). You will get all kind of support including search,rtl, unicode support .
final font = await rootBundle.load("assets/fonts/hind.ttf");
final ttf = Font.ttf(font);
final pdf = pw.Document();
pw.Text(
'Your text',
textDirection:TextDirection.rtl, // If you need in opp direction like urdu
style: pw.TextStyle(
font: ttf,))
If someone still has this problem
final data = await rootBundle.load('assets/fonts/opensans_regular.ttf');
final dataint = data.buffer.asUint8List(data.offsetInBytes,data.lengthInBytes);
final PdfFont font = PdfTrueTypeFont (date,12);
Most of the language not works well with the flutter pdf plugin
In Tamil language, I face problems when two characters merge.
so, i modified the tff with available tools and replaced that character with that character.
as the result, i can able to get the output
String path = 'assets/custom_Anand_MuktaMalar.ttf';
pw.Font? tamilFont = pw.Font.ttf(await rootBundle.load(path));
pw.Text('உவவுமதி உருவின் ஓங்கல் வெண்குடை'.toPrintPdf)
pdf.addPage(
pw.Page(
theme: pw.ThemeData(defaultTextStyle: pw.TextStyle(font: tamilFont)),
));
for further ref, you can see my project:
https://github.com/anandsubbu007/anand-work/tree/BLOC/tamil_pdf