Я использую термопринтер шириной 58 мм, подключенный через Bluetooth, в своем приложении Flutter. Однако при печати PDF-документов, повернутых в альбомный режим, на распечатке возникают проблемы с полосами (нежелательные линии или полосы). Ниже приведен пошаговый процесс создания PDF-файла, преобразования его в изображение, извлечения байтов и отправки на принтер:
как идут дела Future imprimirPdf(
Uint8List bytesPdf,
String mac,
) async {
List bytes = [];
var parametros = await _paramsService.getParams();
var colunas = parametros['parametros']['colunasimpressora'];
PaperSize papel = PaperSize.mm80;
if (colunas != null && colunas.isNotEmpty) {
if (int.parse(colunas) > 0 && int.parse(colunas) < 80) {
papel = PaperSize.mm58;
}
}
CapabilityProfile profile = await CapabilityProfile.load();
Generator generator = Generator(papel, profile);
bytes += await _pdf(generator, bytesPdf);
return imprimir(bytes, mac);
}
Future _pdf(
Generator generator,
Uint8List bytes,
) async {
List dadosBoleto = [];
var image = img.decodePng(bytes)!;
dadosBoleto += generator.imageRaster(image);
return dadosBoleto;
}
//pdf file configuration
doc.addPage(
pw.Page(
pageTheme: const pw.PageTheme(
margin: pw.EdgeInsets.zero,
orientation: pw.PageOrientation.landscape,
pageFormat:
PdfPageFormat(210 * PdfPageFormat.mm, 58 * PdfPageFormat.mm),
),
build: (context) => _content(context),
),
);
final file = File(fileName);
return file.writeAsBytes(await doc.save());
}
pw.Widget _content(pw.Context context) {
return pw.Transform.rotateBox(
angle: math.pi / 2,
child: pw.Container(
child: pw.Row(
children: [...some code here]))}
//when i convert the pdf to image
Future renderPdfImage({required String path}) async {
final PdfImageConverter converter = PdfImageConverter();
Uint8List? image;
await converter.openPdf(path);
image = await converter.renderPage(0, );
if (image != null) {
await converter.saveImage(image, (bool sucess) {});
}
return image!;
}
the document is a converted pdf to image.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ument-58mm