David PHAM-VAN

Allow PdfPreview to send the actual paper size

@@ -441,10 +441,20 @@ class _PdfPreviewState extends State<PdfPreview> { @@ -441,10 +441,20 @@ class _PdfPreviewState extends State<PdfPreview> {
441 } 441 }
442 442
443 Future<void> _print() async { 443 Future<void> _print() async {
  444 + var format = pageFormat;
  445 +
  446 + if (!widget.canChangePageFormat && pages.isNotEmpty) {
  447 + format = PdfPageFormat(
  448 + pages.first.page.width * 72 / dpi,
  449 + pages.first.page.height * 72 / dpi,
  450 + marginAll: 5 * PdfPageFormat.mm,
  451 + );
  452 + }
  453 +
444 final result = await Printing.layoutPdf( 454 final result = await Printing.layoutPdf(
445 onLayout: widget.build, 455 onLayout: widget.build,
446 name: widget.pdfFileName ?? 'Document', 456 name: widget.pdfFileName ?? 'Document',
447 - format: pageFormat, 457 + format: format,
448 ); 458 );
449 459
450 if (result && widget.onPrinted != null) { 460 if (result && widget.onPrinted != null) {