Closed cybersantos closed 2 years ago
@cybersantos I manage to solve it by creating an image then i printing it
First, create unit8list
final bytes = static Future<Uint8List?> multilineTextImage(
String text, [
double width = 375,
]) async {
final recorder = PictureRecorder();
final canvas = Canvas(recorder);
/// Background
final backgroundPaint = Paint()..color = Colors.white;
final backgroundRect = Rect.fromLTRB(width, 10000, 0, 0);
final backgroundPath = Path()
..addRRect(
RRect.fromRectAndRadius(backgroundRect, const Radius.circular(0)),
)
..close();
canvas.drawPath(backgroundPath, backgroundPaint);
final infoPainter = TextPainter(
textDirection: TextDirection.rtl,
text: TextSpan(
text: text,
style: const TextStyle(
color: Colors.black,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
);
infoPainter
..layout(
maxWidth: width,
)
..paint(
canvas,
const Offset(0, 0),
);
final picture = recorder.endRecording();
final pngBytes =
await (await picture.toImage(width.toInt(), infoPainter.height.toInt()))
.toByteData(format: ImageByteFormat.png);
return pngBytes?.buffer.asUint8List();
}
Then print it
BlueThermalPrinter.instance.printImageBytes(bytes)
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
I'm not able to print how the Portuguese characters should be. I've tried several charsets and the result is the same. The printer is a eurosys t9bt02