Flutter:以正确的方向和尺寸A4打印图像

时间:2020-06-23 18:12:51

标签: flutter pdf

我想以抖动方式打印图像。我使用的是包“ printing 3.5.0”。我的问题是现在我要使用页面的空位。但是当我输入方向或大小时,两个参数都将被忽略。

_printImage(GlobalKey globalKey) async {
   final pdf = new PdfDocument();
   final page = new PdfPage(pdf, pageFormat: PdfPageFormat.a4);
   final doc = pw.Document();
   final g = page.getGraphics();

   RenderRepaintBoundary boundary =
       globalKey.currentContext.findRenderObject();
   ui.Image _image = await boundary.toImage();
   var bytes = await _image.toByteData(format: ui.ImageByteFormat.rawRgba);

   PdfImage image = new PdfImage(pdf,
       image: bytes.buffer.asUint8List(),
       width: _image.width,
       height: _image.height);

   doc.addPage(pw.Page(build: (pw.Context context) {
      return pw.Center(
       child: pw.Image(image),
     ); // Center
   }));
   g.drawImage(image, 20.0, 0.0);

   Printing.layoutPdf(onLayout: (pageFormat) {
      return pdf.save();
   });
}

即使我调整图像的宽度和高度,也不会使用整个页面。 不存在可自动缩放整个页面上的图像并观察方向的参数吗?

感谢您的帮助。

0 个答案:

没有答案
相关问题